On Mon, Feb 27, 2023 at 07:39:34AM +0000, Vadim V Konovalov via perl5-porters wrote: > - what's the benefit? Does it fix bug or introduce nice new feature? > Payment is high (in terms of speed 20%) so I guess the benefit is huge > :) A simple example of the class of bug it fixes is: my @a = (1,2,3); sub f { @a = (); print "(@_)\n" }; f(@a, 4); which currently prints undefined or even garbage values, as it is accessing SVs which have been freed or even reallocated. The 20% loss in speed in PERL_RC_STACK builds is *temporary*, and will never appear in a production perl. It's present because, as a *transition* measure, most ops are wrapped. This means to make a function such as pp_const() work on a reference-counted stack, I just changed its definition from PP(pp_const) { ... } to PP_wrapped(pp_const, 0, 0) { ... } On PERL_RC_STACK builds, this declares Perl_pp_const() as a small stub function which calls a function called pp_wrap(), which adjusts the reference count of the arguments on the stack, calls the real pp_const() function, then adjusts the counts again on return. For a simple function like pp_const() which just pushes an SV pointer on the stack, that is a huge extra overhead. Phase two of this project is to go through all the hot and/or simple PP functions and unwrap them. For something simple like pp_const(), that's little more than a 1 line change from XPUSHs(cSVOP_sv); to rpp_xpush_1(cSVOP_sv); Once that has been done, I expect (but can't be certain) that nearly all of that 20% will be reclaimed. Then there will be further optimisations to be made. For example, in PP functions, virtually every need to mortalise a newly-created SV can be eliminated, now that the argument stack will automatically keep the SV alive. At the moment in non void context scope exits, there is a complicated dance to free any temporaries created by the last statement, while not freeing any TEMP return values, while creating TEMP copies of those return args. In a PERL_RC_STACK environment, all that code can be ripped out. > - out of curiosity, is this a TPF grant project? I am being funded via a TPF general perl maintenance grant rather than one for this particular project. -- A major Starfleet emergency breaks out near the Enterprise, but fortunately some other ships in the area are able to deal with it to everyone's satisfaction. -- Things That Never Happen in "Star Trek" #13Thread Previous | Thread Next