Skip to content

pp.c pp_argelem() dont make SV* tmp bufs in a loop to strip GMG #23445

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

bulk88
Copy link
Contributor

@bulk88 bulk88 commented Jul 17, 2025

Alloc the mortal string scratch pad SV* only once and reuse it for every iteration to strip GMG from each SV* key. hv_store_ent() never RC++s ownership of the callers SV* key arg.

Although it makes no difference either way for pp_argelem(), because it is an internal detail of sv.c Use any type of PV COW if available. If a shared HEK COW is delivered into the tmp SV*, even better b/c of hv_store_ent()'s optimization for that.

Worst case keynomg has a Newx() buffer that only reallocs 1x or 2x before flatlining for the rest of the loop which is still very good.

I think, but I can't confirm, that this copy code was added b/c of a GMG getter firing order issue so val doesn't GMG b4 key, or because maybe its not possible to prevent hv_common() keysv GMG from firing so SvGETMAGIC() can't be used to reverse GMG firing order, or maybe if a keysv GMG getter throws an exception inside hv_common(), tmpsv is leaked.

The make multiple mortal SV PVs in a loop code is from day 1 of this opcode in commit 4fa0684 - davem - 7/9/2016 5:41:08 AM

"add OP_ARGELEM, OP_ARGDEFELEM, OP_ARGCHECK ops"


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

Alloc the mortal string scratch pad SV* only once and reuse it for
every iteration to strip GMG from each SV* key. hv_store_ent() never RC++s
ownership of the callers SV* key arg.

Although it makes no difference either way for pp_argelem(), because it is
an internal detail of sv.c Use any type of PV COW if available.
If a shared HEK COW is delivered into the tmp SV*, even better b/c of
hv_store_ent()'s optimization for that.

Worst case keynomg has a Newx() buffer that only reallocs 1x or 2x before
flatlining for the rest of the loop which is still very good.

I think, but I can't confirm, that this copy code was added b/c of a
GMG getter firing order issue so val doesn't GMG b4 key, or because maybe
its not possible to prevent hv_common() keysv GMG from firing so
SvGETMAGIC() can't be used to reverse GMG firing order, or maybe
if a keysv GMG getter throws an exception inside hv_common(),
tmpsv is leaked.

The make multiple mortal SV PVs in a loop code is from day 1 of this
opcode in commit 4fa0684 - davem - 7/9/2016 5:41:08 AM

"add OP_ARGELEM, OP_ARGDEFELEM, OP_ARGCHECK ops"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant