Skip to content

Perl_more_bodies - figure out sizing from sv_type #23360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: blead
Choose a base branch
from

Conversation

richardleach
Copy link
Contributor

Perl_more_bodies allocates and sets up a new arena for the likes of SV body, HE, and HVAUX structs. It has traditionally been called with three arguments:

  • the svtype
  • the size of the structs that the arena will contain
  • the size of the arena to allocate

This commit changes the function definition such that it only takes a single argument: the svtype. From that, and with a bit of additional logic to account of HE and HVAUX using the indexes notionally for SVt_NULL and SVt_IV, Perl_more_bodies can figure out the sizing for itself.

The rationale for this is that:

  • When an application is starting up, the need to call Perl_more_bodies is the unlikely case in each new SV allocation or upgrade.
  • When the application has reached a steady state, the function may not be called regardless of how many SVs are created or upgraded.

With Perl_newSV_type being an inline function, there are a lot of potential callers to this function though, each of which will have two mov instructions for pushing the two size parameters onto the stack should the need to call Perl_more_bodies arise. Removing two instructions from each potential call site should help reduce binary size a little and avoid taking up unnecessary space in the CPU's instruction buffer.


  • This set of changes does not require a perldelta entry.

@richardleach richardleach added the defer-next-dev This PR should not be merged yet, but await the next development cycle label Jun 9, 2025
@bulk88
Copy link
Contributor

bulk88 commented Jun 10, 2025

I like this patch. It is long overdue.

`Perl_more_bodies` allocates and sets up a new arena for the likes of
SV body, HE, and HVAUX structs. It has traditionally been called with
three arguments:
  * the `svtype`
  * the size of the structs that the arena will contain
  * the size of the arena to allocate

This commit changes the function definition such that it only takes
a single argument: the `svtype`. From that, and with a bit of
additional logic to account of HE and HVAUX using the indexes
notionally for SVt_NULL and SVt_IV, `Perl_more_bodies` can figure
out the sizing for itself.

The rationale for this is that:
  * When an application is starting up, the need to call `Perl_more_bodies`
    is the unlikely case in each new SV allocation or upgrade.
  * When the application has reached a steady state, the function
    may not be called regardless of how many SVs are created or upgraded.

With `Perl_newSV_type` being an inline function, there are a lot of
potential callers to this function though, each of which will have
two `mov` instructions for pushing the two size parameters onto the
stack should the need to call `Perl_more_bodies` arise. Removing two
instructions from each potential call site should help reduce binary
size a little and avoid taking up unnecessary space in the CPU's
instruction buffer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defer-next-dev This PR should not be merged yet, but await the next development cycle
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants