Skip to content

Commit

Permalink
grow the tmps (mortal) stack exponentially rather than linearly
Browse files Browse the repository at this point in the history
As with the value stack and the save stack, this gives us constant
amortized growth per element.

After this patch the profiler shows the "SvPV_shrink_to_cur(sv)"
and "sv = sv_2mortal(newSV(80))" calls in do_readline as the
hotspots for the io unheated test case, using 55% of the measured
time in total.

Fixes Perl#21654
  • Loading branch information
tonycoz committed Nov 23, 2023
1 parent b2bbe7d commit a4a7099
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions scope.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,12 @@ Perl_tmps_grow_p(pTHX_ SSize_t ix)
{
SSize_t extend_to = ix;
#ifndef STRESS_REALLOC
if (ix - PL_tmps_max < 128)
extend_to += (PL_tmps_max < 512) ? 128 : 512;
SSize_t grow_size = PL_tmps_max < 512 ? 128 : PL_tmps_max / 5;
if (extend_to >= SSize_t_MAX - grow_size)
/* trigger memwrap message or fail allocation */
extend_to = SSize_t_MAX-1;
else
extend_to += grow_size;
#endif
Renew(PL_tmps_stack, extend_to + 1, SV*);
PL_tmps_max = extend_to + 1;
Expand Down

0 comments on commit a4a7099

Please sign in to comment.