Dedicated SV copying code in place of Perl_sv_setsv_flags
Perl_sv_setsv_flags is the heavyweight function for assigning the value(s) of
a source SV to a destination SV. It contains many branches for preparing the
destination SV prior to assignment. However:
- If the destination SV has just been created, much of that logic isn't needed.
- When cloning a SV, simple assignments (particularly IVs and PVs) dominate.
This set of commits:
- Extracts the "is this CoWable?" test from
Perl_sv_setsv_flagsinto a macro. - Adds
Perl_sv_freshcopy_flagsand two static helper functions. - Modifies
Perl_newSVsv_flagsandPerl_sv_mortalcopy_flagsto use them. - Standardizes a number of call sites that did their own things but really
should use
Perl_newSVsv_flagsorPerl_sv_mortalcopy_flags.
Using perl's test harness as a guide:
- Bodyless code handles 45% of calls to
Perl_newSVsv_flagsand 57% of calls toPerl_sv_mortalcopy_flags. - The
SVt_PV/SVp_POKcode handles 32% of calls toPerl_newSVsv_flagsand 36% of calls toPerl_sv_mortalcopy_flags. S_sv_freshcopy_flagscode handles 95% of the remainder inPerl_newSVsv_flagsand 91% of the remainder in toPerl_sv_mortalcopy_flags.
With these changes compared with a build of blead:
-
perl -e 'for (1..100_000) { my $x = [ (1) x 1000 ]; }'runs 10% faster -
perl -e 'for (1..100_000) { my $x = [ ("Perl") x 250 ]; }'runs 45% faster
- This set of changes does require a perldelta entry and I'll write one post-merge.
Cloning is rather unfortunate choice of words, given that it has a very specific meaning in our codebase that is quite different from what this PR is about. Renaming the PR may be helpful.
I've made a lot of changes following earlier comments - thanks for those - and have finally force-pushed.
These changes aren't complete. For example:
- Measured performance seems worse than in the PR version, so I need to look into that
- Might change sflag handling/ SvFLAGS(dsv) setting
- Not settled on struct membet initialisation
- Might still rename the function that is currently
Perl_newSVsv_flagsand havenewSVsv_flagsbe a macro that checks(ssv)before calling the sv.c function.
The last commit could use a better commit message than "bulk88 comments" :)
I've squashed recent comment-addressing commits. Will have a final read over the source code comments at the weekend. Hopefully then, apart from any clarifications on the open conversations or further review comments, this will be ready to merge.
Rebased to clear merge conflicts.
Rebased for perldelta conflict.
Ready for any final reviews.
the last commit's message indicates it should be squashed
Thanks, I've hopefully addressed those comments and squashed all trailing commits.
Many thanks for all the reviews @tonycoz & @bulk88 - it's a relief to finally get this in before the github-actions bot adds the hasConflicts flag again!