Skip to content

Commit 3a2cf3b

Browse files
committed
sv.c: Add S_sv_freshcopy_flags and S_sv_freshcopy_POK
S_sv_freshcopy_flags is a drop-in replacement for `Perl_sv_setsv_flags`. It is designed for use when the destination SV is being freshly created and much of the logic in `sv_setsv_flags` is irrelevant. The intended users for this new function are: * Perl_sv_mortalcopy_flags * Perl_newSVsv_flags Those functions have been modified such that: * Bodyless destination SVs are created inline * SVt_PVs also have special casing * SVt_PVMG and below use S_sv_freshcopy_flags * Anything else drops back to using Perl_sv_setsv_flags S_sv_freshcopy_POK is a helper function that concentrates on the string assignment logic: * Swipe the buffer * CoW the buffer * Copy the buffer Using perl's test harness as a guide: * 45% of Perl_newSVsv_flags / 57% of Perl_sv_mortalcopy_flags calls use the bodyless code * 32% of Perl_newSVsv_flags / 36% of Perl_sv_mortalcopy_flags calls use the SVt_PV/SVp_POK code * The S_sv_freshcopy_flags code handles the bulk of the remainder. With these changes compared with a build of blead: * `perl -e 'for (1..100_000) { my $x = [ (1) x 1000 ]; }'` runs 30% faster * `perl -e 'for (1..100_000) { my $x = [ ("Perl") x 1000 ]; }' runs: * 15% faster if `newSV_type(SVt_PV)` is NOT inlined * 30% faster if it IS inlined The overall reduction in branches when cloning SVs, and refocusing of branch prediction within Perl_sv_setsv_flags, will hopefully give a meaningful boost to realistic Perl applications.
1 parent 68c014c commit 3a2cf3b

File tree

1 file changed

+401
-19
lines changed

1 file changed

+401
-19
lines changed

0 commit comments

Comments
 (0)