-
Notifications
You must be signed in to change notification settings - Fork 584
Add OPpTARGET_MY optimization to OP_UNDEF #20077
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
Add OPpTARGET_MY optimization to OP_UNDEF #20077
Conversation
326a946
to
dfb999f
Compare
dfb999f
to
3594208
Compare
Rebased following OP_PADSV_STORE merge. Awaiting some reviewers. |
This isn't just an optree optimization. Without this patch:
With this patch:
This may be a reasonable change, but would at least need to be noted in the commit message. |
Good point. I think the existing behaviour should be preserved. If there's a flag spare, it looks straightforward to implement. |
On Tue, 23 Aug 2022 at 13:52, Richard Leach ***@***.***> wrote:
This isn't just an optree optimization. undef $x and $x = undef have different behavior. $x = undef leaves a PV allocated, but clears its flags. This means re-using the variable for a string of the same size will not allocate any new memory.
Good point. I think the existing behaviour should be preserved. If there's a flag spare, it looks straightforward to implement.
I vote that the existing behavior be preserved, it can have some
interesting performance implications.
cheers,
Yves
…--
perl -Mre=debug -e "/just|another|perl|hacker/"
|
On Tue, 23 Aug 2022 at 15:25, demerphq ***@***.***> wrote:
On Tue, 23 Aug 2022 at 13:52, Richard Leach ***@***.***> wrote:
...
> Good point. I think the existing behaviour should be preserved. If there's a flag spare, it looks straightforward to implement.
I vote that the existing behavior be preserved, it can have some
interesting performance implications.
Sorry i phrased that poorly. I understand you just said you would do
that, i just meant to add that there is good reason to do so.
Appreciate your efforts on this stuff.
cheers,
Yves
…--
perl -Mre=debug -e "/just|another|perl|hacker/"
|
3594208
to
b06b35c
Compare
That's okay, I understood it as you meant it. The current branch should now preserve the pre-existing behaviour w.r.t. PVs:
I've added the tests you suggested to t/perf/opcount.t, will just tidy them slightly so they don't break unnecessarily in the next opcode update. |
b06b35c
to
a286f49
Compare
Ok. tests tidied. I think all review comments to date have been addressed. |
This allows the existing `undef` OP to act on a pad SV. The following two cases are optimized: `undef my $x`, currently implemented as: 4 <1> undef vK/1 ->5 3 <0> padsv[$x:1,2] sRM/LVINTRO ->4 `my $a = undef`, currently implemented as: 5 <2> sassign vKS/2 ->6 3 <0> undef s ->4 4 <0> padsv[$x:1,2] sRM*/LVINTRO ->5 These are now just represented as: 3 <1> undef[$x:1,2] vK/SOMEFLAGS ->4 Note: The two cases are not quite functionally identical, as `$x = undef` clears the SV flags but preserves any PV allocation for later reuse, whereas `undef $x` does free any PV allocation. This behaviour difference is preserved through use of the OPpUNDEF_KEEP_PV flag.
a286f49
to
2e69278
Compare
Looks good to me again today,. :-) |
This allows the existing
undef
OP to act on a pad SV. The followingtwo cases are optimized:
undef my $x
, currently implemented as:my $a = undef
, currently implemented as:These are now just represented as:
3 <1> undef[$x:1,2] vK/LVINTRO,TARGMY ->4
The
undef $x
case gets a slight performance boost, as shown in this toy example:my $x; for (0..10_000_000) { undef $x; undef $x; undef $x; undef $x; undef $x; undef $x; undef $x; undef $x; undef $x; undef $x }
Blead:
Patched:
The
$x = undef
case, in which more optimization is achieved, performs much better, as shown in this toy example:my $x; for (0..10_000_000) { $x = undef; $x = undef; $x = undef; $x = undef; $x = undef; $x = undef; $x = undef; $x = undef; $x = undef; $x = undef }
Patched:
Also some bench.pl comparisons: