Branch: refs/heads/blead
  Home:   https://github.com/Perl/perl5
  Commit: 0bc1c52a36a6c2d50a5798039f4d5e5daf5880b3
      
https://github.com/Perl/perl5/commit/0bc1c52a36a6c2d50a5798039f4d5e5daf5880b3
  Author: Richard Leach <[email protected]>
  Date:   2026-07-16 (Thu, 16 Jul 2026)

  Changed paths:
    M op.c
    M pad.c

  Log Message:
  -----------
  S_maybe_targlex: don't leak the unused PADTMP pad slot

The TARGMY optimization converts an optree like this:

    <2> sassign [no pad slot allocated]
        <2> some_op [pad slot B allocated]
        <1> padsv [pad slot A allocated]

into:

    <2> some_op [pad slot A swiped]

using the code:

  swipe_and_detach:
    kid->op_targ = kkid->op_targ; <--- some_op now points to slot A
    kkid->op_targ = 0;            <--- padsv doesn't point to any slot
    /* Now we do not need PADSV and SASSIGN.
    * Detach kid and free the rest. */
    op_sibling_splice(o, NULL, 1, NULL);
    op_free(o);
    return kid;

At this point, slot B has been abandoned but not made available for
any newly created OPs to use. The slot is filled, but serves no purpose.

This commit swaps the `op_targ` values of `kid` and `kkid`, so that
when `kkid` is freed, slot B is made available for reuse. It also ensures
that new PADTMP and CONST type searches for available slots start at this
slot, rather than just after it.

At run time, potentially lower pad sizes and better memory locality may
help with overall performance. At compile time, activities like
`S_pad_findlex` scanning through the pad to resolve a variable is more
efficient if the pad isn't littered with holes from abandoned slots.

Pad sizes and savings will greatly vary, from mimimal to meaningful.
Notable outliers in the difference in slots "used" within core include:
 * ExtUtils::MM_Any::_add_requirements_to_meta      71 ->  41
 * HTTP::Tiny::_prepare_headers_and_cb             167 -> 110
 * Pod::Html::process_options                      128 ->  74
 * Term::Table::init                                80 ->  52
 * Test2::API::Context::init                        36 ->  23
 * Test2::Event::Plan::facet_data                   44 ->  28
 * Time::Piece::use_locale                          91 ->  68
 * Unicode::Collate::new                           101 ->  66


  Commit: a4c4abfb937d4089368bb9eb9bde4ea3021a39b0
      
https://github.com/Perl/perl5/commit/a4c4abfb937d4089368bb9eb9bde4ea3021a39b0
  Author: Richard Leach <[email protected]>
  Date:   2026-07-16 (Thu, 16 Jul 2026)

  Changed paths:
    M op.c

  Log Message:
  -----------
  Move S_maybe_targlex in preparation for the next commit


  Commit: edc77d1b36336920f654386bb10a9701c62337d0
      
https://github.com/Perl/perl5/commit/edc77d1b36336920f654386bb10a9701c62337d0
  Author: Richard Leach <[email protected]>
  Date:   2026-07-16 (Thu, 16 Jul 2026)

  Changed paths:
    M op.c

  Log Message:
  -----------
  S_maybe_targlex now runs before an OP_SASSIGN is created, instead of after

Prior to this commit, `Perl_ck_sassign` would call `S_maybe_targlex` to
try and unpick the `OP_SASSIGN` just created.

With this commit, `Perl_newBINOP` instead calls `S_maybe_targlex` before
trying to build the `OP_SASSIGN`. This reduces the churn associated with
OP and pad slot allocation/deallocation.

`Perl_newBINOP` already checked to see if `type != OP_SASSIGN`, so
this change adds only a small branch when that condition is not met.


Compare: https://github.com/Perl/perl5/compare/0104e1184b9b...edc77d1b3633

To unsubscribe from these emails, change your notification settings at 
https://github.com/Perl/perl5/settings/notifications

Reply via email to