You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
CV symbol table optimization only works in main:: #15671
Here's the merge I'm talking about:
http://perl5.git.perl.org/perl.git/commitdiff/f9d9e965
Also listed in perl5220delta:
Subroutines in packages no longer need to be stored in typeglobs:
declaring a subroutine will now put a simple sub reference directly in
the stash if possible, saving memory.
'ec' stands for "error count"; this is normally false (unless we're
parsing past a syntax error).
The 'name' check is fine (name = "foo", namlen = 3); what's tripping us
up is the stash check.
PL_curstash is \%X:: in this situation, but CopSTASH(PL_curcop) is
\%main::. So the stashes differ and we land in the gv_fetch_flags path,
which adds a full typeglob.
PL_curstash is \%X:: in this situation, but CopSTASH(PL_curcop) is
\%main::. So the stashes differ and we land in the gv_fetch_flags
path,
which adds a full typeglob.
Here's the merge I'm talking about:
http://perl5.git.perl.org/perl.git/commitdiff/f9d9e965
Also listed in perl5220delta:
Subroutines in packages no longer need to be stored in typeglobs:
declaring a subroutine will now put a simple sub reference directly in
the stash if possible, saving memory.
From e4b2a8e44465712094f2d4e76fe75f70bd3e1b49 Mon Sep 17 00:00:00 2001
From: Lukas Mai <l.mai@web.de>
Date: Fri, 21 Oct 2016 15:04:39 +0200
Subject: [PATCH] t/op/sub.t: add a TODO test for RT #129916
---
t/op/sub.t | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/t/op/sub.t b/t/op/sub.t
index 07fa033..5c501b1 100644
--- a/t/op/sub.t+++ b/t/op/sub.t@@ -6,7 +6,7 @@ BEGIN {
set_up_inc('../lib');
}
-plan(tests => 63);+plan(tests => 65);
sub empty_sub {}
@@ -416,6 +416,17 @@ sub curpm {
"a" =~ /(.)/;
is(curpm(), 'c', 'return and PL_curpm');
+sub rt_129916 { 42 }+is ref($main::{rt_129916}), 'CODE', 'simple sub stored as CV in stash (main::)';+{+ package RT129916;+ sub foo { 42 }+}+{+ local $TODO = "CV symbol table optimization only works in main:: [perl #129916]";+ is ref($RT129916::{foo}), 'CODE', 'simple sub stored as CV in stash (non-main::)';+}+
# [perl #129090] Crashes and hangs
watchdog 10;
{ no warnings;
--
2.10.0
On Wed, 19 Oct 2016 14:20:42 GMT, mauke- wrote:
This is a bug report for perl from l.mai@web.de,
generated with the help of perlbug 1.40 running under perl 5.24.0.
-----------------------------------------------------------------
[Please describe your issue here]
Here's the merge I'm talking about:
http://perl5.git.perl.org/perl.git/commitdiff/f9d9e965
Also listed in perl5220delta:
Subroutines in packages no longer need to be stored in typeglobs:
declaring a subroutine will now put a simple sub reference directly in
the stash if possible, saving memory.
'ec' stands for "error count"; this is normally false (unless we're
parsing past a syntax error).
The 'name' check is fine (name = "foo", namlen = 3); what's tripping
us
up is the stash check.
PL_curstash is \%X:: in this situation, but CopSTASH(PL_curcop) is
\%main::. So the stashes differ and we land in the gv_fetch_flags
path,
which adds a full typeglob.
Is this something where, for the short run, we would be best off simply noting the phenomenon in the documentation? I.e., something along the lines of:
#####
Contrary to what was stated in pod/perl5220delta.pod, ...
#####
On Fri, 30 Dec 2016 16:42:52 -0800, jkeenan wrote:
Is this something where, for the short run, we would be best off
simply noting the phenomenon in the documentation? I.e., something
along the lines of:
#####
Contrary to what was stated in pod/perl5220delta.pod, ...
#####
Thank you very much.
Unnecessarily allocating a GV when an RV will do can lead to program bloat. (160 bytes vs 24 bytes on 64 bit). This would be a very good thing to fix.
On Wed, 19 Oct 2016 07:20:42 -0700, mauke- wrote:
This is a bug report for perl from l.mai@web.de,
generated with the help of perlbug 1.40 running under perl 5.24.0.
-----------------------------------------------------------------
[Please describe your issue here]
Here's the merge I'm talking about:
http://perl5.git.perl.org/perl.git/commitdiff/f9d9e965
Also listed in perl5220delta:
Subroutines in packages no longer need to be stored in typeglobs:
declaring a subroutine will now put a simple sub reference directly in
the stash if possible, saving memory.
$ perl -wE 'package Other; sub foo { 42 } say $Other::{foo}'
*Other::foo
I.e. this optimization doesn't apply to modules, which is where most
subroutines come from.
Fixing it causes this to fail:
use Test::More tests => 1;
package Other;
sub f1 { "f1" }
local $Other::{"f1"} = sub { "h1" };
::is(f1(), "h1", "localised sub via stash");
Does this matter? This is pretty obscure code (from t/op/local.t) that should probably be doing local *Other::f1 = sub { "h1" } instead (if it were production code).
On Mon, 28 Aug 2017 20:33:55 -0700, sprout wrote:
On Wed, 19 Oct 2016 07:20:42 -0700, mauke- wrote:
This is a bug report for perl from l.mai@web.de,
generated with the help of perlbug 1.40 running under perl 5.24.0.
-----------------------------------------------------------------
[Please describe your issue here]
Here's the merge I'm talking about:
http://perl5.git.perl.org/perl.git/commitdiff/f9d9e965
Also listed in perl5220delta:
Subroutines in packages no longer need to be stored in typeglobs:
declaring a subroutine will now put a simple sub reference directly
in
the stash if possible, saving memory.
$ perl -wE 'package Other; sub foo { 42 } say $Other::{foo}'
*Other::foo
I.e. this optimization doesn't apply to modules, which is where most
subroutines come from.
Fixing it causes this to fail:
use Test::More tests => 1;
package Other;
sub f1 { "f1" }
local $Other::{"f1"} = sub { "h1" };
::is(f1(), "h1", "localised sub via stash");
Does this matter? This is pretty obscure code (from t/op/local.t)
that should probably be doing local *Other::f1 = sub { "h1" } instead
(if it were production code).
It’s possible to add a special case to save_helem_flags such that it treats stashes differently. Basically, the rv2cv op in the f1() call above references the actual scalar that $Other::{f1} points to, so if localization swaps out a different scalar (which happens with local $Other::{f1}) the stash no longer points to the scalar that the op points to. GVs in stashes are already treated specially. Maybe subrefs in stashes should be treated the same way.
On Mon, 28 Aug 2017 20:33:55 -0700, sprout wrote:
On Wed, 19 Oct 2016 07:20:42 -0700, mauke- wrote:
This is a bug report for perl from l.mai@web.de,
generated with the help of perlbug 1.40 running under perl 5.24.0.
-----------------------------------------------------------------
[Please describe your issue here]
Here's the merge I'm talking about:
http://perl5.git.perl.org/perl.git/commitdiff/f9d9e965
Also listed in perl5220delta:
Subroutines in packages no longer need to be stored in typeglobs:
declaring a subroutine will now put a simple sub reference directly
in
the stash if possible, saving memory.
$ perl -wE 'package Other; sub foo { 42 } say $Other::{foo}'
*Other::foo
I.e. this optimization doesn't apply to modules, which is where most
subroutines come from.
Fixing it causes this to fail:
Could you precise the 'fixing it' part. Where/what is the patch with your fix candidate ? is there any commit id / topic branch where we could read your attempt to fix it ?
thanks
use Test::More tests => 1;
package Other;
sub f1 { "f1" }
local $Other::{"f1"} = sub { "h1" };
::is(f1(), "h1", "localised sub via stash");
Does this matter? This is pretty obscure code (from t/op/local.t)
that should probably be doing local *Other::f1 = sub { "h1" } instead
(if it were production code).
On Mon, 18 Sep 2017 09:00:58 -0700, atoomic wrote:
On Mon, 28 Aug 2017 20:33:55 -0700, sprout wrote:
On Wed, 19 Oct 2016 07:20:42 -0700, mauke- wrote:
This is a bug report for perl from l.mai@web.de,
generated with the help of perlbug 1.40 running under perl 5.24.0.
-----------------------------------------------------------------
[Please describe your issue here]
Here's the merge I'm talking about:
http://perl5.git.perl.org/perl.git/commitdiff/f9d9e965
Also listed in perl5220delta:
Subroutines in packages no longer need to be stored in typeglobs:
declaring a subroutine will now put a simple sub reference directly
in
the stash if possible, saving memory.
$ perl -wE 'package Other; sub foo { 42 } say $Other::{foo}'
*Other::foo
I.e. this optimization doesn't apply to modules, which is where
most
subroutines come from.
Fixing it causes this to fail:
Could you precise the 'fixing it' part. Where/what is the patch with
your fix candidate ? is there any commit id / topic branch where we
could read your attempt to fix it ?
Due to test failures, I had not actually committed it yet. But now I have. It is the ‘unfinished’ commit on the sprout/cv-in-stash branch.
use Test::More tests => 1;
package Other;
sub f1 { "f1" }
local $Other::{"f1"} = sub { "h1" };
::is(f1(), "h1", "localised sub via stash");
Does this matter? This is pretty obscure code (from t/op/local.t)
that should probably be doing local *Other::f1 = sub { "h1" } instead
(if it were production code).
Hi Father Chrysostomos, Todd R. and I checked your branch sprout/cv-in-stash and had a look at the issue from the extract from t/op/local.t, which is failing.
Hope this patch could help, but looks like the OP multideref is not calling the Perl_mro_method_changed_in via a regular save_gp call.
We came with this lazy solution (view attached patch) which force to upgrade the RV/CV to a GV.
As these cases are probably uncommon, I think it's a solution we could consider when using local on a CV.
Also, notice that some other OPs might require the same kind of action.
I’ve also attached to this case a simple test (with some comments) to show the problem.
sincerely
nicolas
On Thu, 21 Sep 2017 09:34:42 -0700, sprout wrote:
On Mon, 18 Sep 2017 09:00:58 -0700, atoomic wrote:
On Mon, 28 Aug 2017 20:33:55 -0700, sprout wrote:
On Wed, 19 Oct 2016 07:20:42 -0700, mauke- wrote:
This is a bug report for perl from l.mai@web.de,
generated with the help of perlbug 1.40 running under perl
5.24.0.
-----------------------------------------------------------------
[Please describe your issue here]
Here's the merge I'm talking about:
http://perl5.git.perl.org/perl.git/commitdiff/f9d9e965
Also listed in perl5220delta:
Subroutines in packages no longer need to be stored in typeglobs:
declaring a subroutine will now put a simple sub reference
directly
in
the stash if possible, saving memory.
$ perl -wE 'package Other; sub foo { 42 } say $Other::{foo}'
*Other::foo
I.e. this optimization doesn't apply to modules, which is where
most
subroutines come from.
Fixing it causes this to fail:
Could you precise the 'fixing it' part. Where/what is the patch with
your fix candidate ? is there any commit id / topic branch where we
could read your attempt to fix it ?
Due to test failures, I had not actually committed it yet. But now I
have. It is the ‘unfinished’ commit on the sprout/cv-in-stash branch.
use Test::More tests => 1;
package Other;
sub f1 { "f1" }
local $Other::{"f1"} = sub { "h1" };
::is(f1(), "h1", "localised sub via stash");
Does this matter? This is pretty obscure code (from t/op/local.t)
that should probably be doing local *Other::f1 = sub { "h1" }
instead
(if it were production code).
From 77ab33315c43b3a61a588d1f9ba5adfa9cf0914d Mon Sep 17 00:00:00 2001
From: Nicolas R <atoomic@cpan.org>
Date: Thu, 21 Sep 2017 17:30:06 -0500
Subject: [PATCH] Adjust OP multideref for RV/CV
When the sv is not a GV but one reference
to a CV, force to coerce it to a GV using CvGV
then treat it as a regular GV.
---
pp_hot.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/pp_hot.c b/pp_hot.c
index 7fc48e1a79..d7db038fff 100644
--- a/pp_hot.c+++ b/pp_hot.c@@ -3000,6 +3000,9 @@ PP(pp_multideref)
}
else {
if (localizing) {
+ if ( SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV && CvNAMED(SvRV(*svp)) ) {+ sv = (SV*) CvGV( SvRV(sv) );+ }
if (HvNAME_get(hv) && isGV(sv))
save_gp(MUTABLE_GV(sv),
!(PL_op->op_flags & OPf_SPECIAL));
--
2.14.1
In addition to my previous emaul, you would found attached to this message a minor update of the multideref patch which uses 'sv' instead of '*svp'.
After running the tests from 'sprout/cv-in-stash' with this additional patch only 3 tests fail:
../ext/B/t/xref.t
../ext/XS-APItest/t/gv_fetchmeth.t
../lib/B/Deparse.t
I've attached a fix for the B::Xref one, hope the other are not so hard to fix.
That should leave us with only failures
nicolas
On Thu, 21 Sep 2017 15:52:42 -0700, atoomic wrote:
Hi Father Chrysostomos, Todd R. and I checked your branch sprout/cv-
in-stash and had a look at the issue from the extract from
t/op/local.t, which is failing.
Hope this patch could help, but looks like the OP multideref is not
calling the Perl_mro_method_changed_in via a regular save_gp call.
We came with this lazy solution (view attached patch) which force to
upgrade the RV/CV to a GV.
As these cases are probably uncommon, I think it's a solution we could
consider when using local on a CV.
Also, notice that some other OPs might require the same kind of
action.
I’ve also attached to this case a simple test (with some comments) to
show the problem.
sincerely
nicolas
On Thu, 21 Sep 2017 09:34:42 -0700, sprout wrote:
On Mon, 18 Sep 2017 09:00:58 -0700, atoomic wrote:
On Mon, 28 Aug 2017 20:33:55 -0700, sprout wrote:
On Wed, 19 Oct 2016 07:20:42 -0700, mauke- wrote:
This is a bug report for perl from l.mai@web.de,
generated with the help of perlbug 1.40 running under perl
5.24.0.
-----------------------------------------------------------------
[Please describe your issue here]
Here's the merge I'm talking about:
http://perl5.git.perl.org/perl.git/commitdiff/f9d9e965
Also listed in perl5220delta:
Subroutines in packages no longer need to be stored in
typeglobs:
declaring a subroutine will now put a simple sub reference
directly
in
the stash if possible, saving memory.
$ perl -wE 'package Other; sub foo { 42 } say $Other::{foo}'
*Other::foo
I.e. this optimization doesn't apply to modules, which is where
most
subroutines come from.
Fixing it causes this to fail:
Could you precise the 'fixing it' part. Where/what is the patch
with
your fix candidate ? is there any commit id / topic branch where we
could read your attempt to fix it ?
Due to test failures, I had not actually committed it yet. But now I
have. It is the ‘unfinished’ commit on the sprout/cv-in-stash
branch.
use Test::More tests => 1;
package Other;
sub f1 { "f1" }
local $Other::{"f1"} = sub { "h1" };
::is(f1(), "h1", "localised sub via stash");
Does this matter? This is pretty obscure code (from
t/op/local.t)
that should probably be doing local *Other::f1 = sub { "h1" }
instead
(if it were production code).
Activity
p5pRT commentedon Oct 19, 2016
From @mauke
Created by @mauke
Here's the merge I'm talking about:
http://perl5.git.perl.org/perl.git/commitdiff/f9d9e965
Also listed in perl5220delta:
Subroutines in packages no longer need to be stored in typeglobs:
declaring a subroutine will now put a simple sub reference directly in
the stash if possible, saving memory.
This works fine for the main script:
$ perl -wE 'sub foo { 42 } say $main::{foo}'
CODE(0xa06f668)
But not in other packages:
$ perl -wE 'package Other; sub foo { 42 } say $Other::{foo}'
*Other::foo
I.e. this optimization doesn't apply to modules, which is where most
subroutines come from.
-----
Speculation follows.
I suspect this is due to the following code in op.c (Perl_newATTRSUB_x):
const I32 flags =
ec ? GV_NOADD_NOINIT
: PL_curstash != CopSTASH(PL_curcop)
|| memchr(name, ':', namlen) || memchr(name, '\'', namlen)
? gv_fetch_flags
: GV_ADDMULTI | GV_NOINIT | GV_NOTQUAL;
gv = gv_fetchsv(cSVOPo->op_sv, flags, SVt_PVCV);
'ec' stands for "error count"; this is normally false (unless we're
parsing past a syntax error).
The 'name' check is fine (name = "foo", namlen = 3); what's tripping us
up is the stash check.
PL_curstash is \%X:: in this situation, but CopSTASH(PL_curcop) is
\%main::. So the stashes differ and we land in the gv_fetch_flags path,
which adds a full typeglob.
Perl Info
p5pRT commentedon Oct 19, 2016
From @mauke
On Wed Oct 19 07:20:42 2016, mauke- wrote:
I think this is the same underlying problem as https://rt-archive.perl.org/perl5/Ticket/Display.html?id=129239.
p5pRT commentedon Oct 21, 2016
From @mauke
On Wed Oct 19 07:20:42 2016, mauke- wrote:
Here's a patch that adds a TODO test for now.
p5pRT commentedon Oct 21, 2016
From @mauke
0001-t-op-sub.t-add-a-TODO-test-for-RT-129916.patch
p5pRT commentedon Dec 31, 2016
From @jkeenan
On Wed, 19 Oct 2016 14:20:42 GMT, mauke- wrote:
Is this something where, for the short run, we would be best off simply noting the phenomenon in the documentation? I.e., something along the lines of:
#####
Contrary to what was stated in pod/perl5220delta.pod, ...
#####
Thank you very much.
--
James E Keenan (jkeenan@cpan.org)
p5pRT commentedon Dec 31, 2016
The RT System itself - Status changed from 'new' to 'open'
p5pRT commentedon Aug 11, 2017
From @toddr
On Fri, 30 Dec 2016 16:42:52 -0800, jkeenan wrote:
Unnecessarily allocating a GV when an RV will do can lead to program bloat. (160 bytes vs 24 bytes on 64 bit). This would be a very good thing to fix.
Todd
p5pRT commentedon Aug 29, 2017
From @cpansprout
On Wed, 19 Oct 2016 07:20:42 -0700, mauke- wrote:
Fixing it causes this to fail:
use Test::More tests => 1;
package Other;
sub f1 { "f1" }
local $Other::{"f1"} = sub { "h1" };
::is(f1(), "h1", "localised sub via stash");
Does this matter? This is pretty obscure code (from t/op/local.t) that should probably be doing local *Other::f1 = sub { "h1" } instead (if it were production code).
--
Father Chrysostomos
p5pRT commentedon Aug 29, 2017
From @cpansprout
On Mon, 28 Aug 2017 20:33:55 -0700, sprout wrote:
It’s possible to add a special case to save_helem_flags such that it treats stashes differently. Basically, the rv2cv op in the f1() call above references the actual scalar that $Other::{f1} points to, so if localization swaps out a different scalar (which happens with local $Other::{f1}) the stash no longer points to the scalar that the op points to. GVs in stashes are already treated specially. Maybe subrefs in stashes should be treated the same way.
--
Father Chrysostomos
p5pRT commentedon Sep 18, 2017
From @atoomic
On Mon, 28 Aug 2017 20:33:55 -0700, sprout wrote:
Could you precise the 'fixing it' part. Where/what is the patch with your fix candidate ? is there any commit id / topic branch where we could read your attempt to fix it ?
thanks
p5pRT commentedon Sep 21, 2017
From @cpansprout
On Mon, 18 Sep 2017 09:00:58 -0700, atoomic wrote:
Due to test failures, I had not actually committed it yet. But now I have. It is the ‘unfinished’ commit on the sprout/cv-in-stash branch.
--
Father Chrysostomos
p5pRT commentedon Sep 21, 2017
From @atoomic
Hi Father Chrysostomos, Todd R. and I checked your branch sprout/cv-in-stash and had a look at the issue from the extract from t/op/local.t, which is failing.
Hope this patch could help, but looks like the OP multideref is not calling the Perl_mro_method_changed_in via a regular save_gp call.
We came with this lazy solution (view attached patch) which force to upgrade the RV/CV to a GV.
As these cases are probably uncommon, I think it's a solution we could consider when using local on a CV.
Also, notice that some other OPs might require the same kind of action.
I’ve also attached to this case a simple test (with some comments) to show the problem.
sincerely
nicolas
On Thu, 21 Sep 2017 09:34:42 -0700, sprout wrote:
p5pRT commentedon Sep 21, 2017
From @atoomic
0001-Adjust-OP-multideref-for-RV-CV.patch
p5pRT commentedon Sep 21, 2017
From @atoomic
test-extract.pl
p5pRT commentedon Sep 21, 2017
From @atoomic
In addition to my previous emaul, you would found attached to this message a minor update of the multideref patch which uses 'sv' instead of '*svp'.
After running the tests from 'sprout/cv-in-stash' with this additional patch only 3 tests fail:
../ext/B/t/xref.t
../ext/XS-APItest/t/gv_fetchmeth.t
../lib/B/Deparse.t
I've attached a fix for the B::Xref one, hope the other are not so hard to fix.
That should leave us with only failures
nicolas
On Thu, 21 Sep 2017 15:52:42 -0700, atoomic wrote:
12 remaining items
p5pRT commentedon Oct 15, 2017
From @jkeenan
Re-opening this ticket, as the final commit referenced appears to have caused large BBC problems (RT 132252).
Thank you very much.
--
James E Keenan (jkeenan@cpan.org)
p5pRT commentedon Oct 15, 2017
@jkeenan - Status changed from 'pending release' to 'open'
p5pRT commentedon Nov 11, 2017
From @cpansprout
On Sun, 15 Oct 2017 13:12:28 -0700, jkeenan wrote:
The optimisation was reverted in commit 6eed25e and has now been reinstated in commit d964025.
--
Father Chrysostomos
p5pRT commentedon Nov 11, 2017
@cpansprout - Status changed from 'open' to 'pending release'
p5pRT commentedon Jun 23, 2018
From @khwilliamson
Thank you for filing this report. You have helped make Perl better.
With the release yesterday of Perl 5.28.0, this and 185 other issues have been
resolved.
Perl 5.28.0 may be downloaded via:
https://metacpan.org/release/XSAWYERX/perl-5.28.0
If you find that the problem persists, feel free to reopen this ticket.
p5pRT commentedon Jun 23, 2018
@khwilliamson - Status changed from 'pending release' to 'resolved'
op.c: re-enable coderef-in-stash optimization
op.c: re-enable coderef-in-stash optimization
Reapply "op.c: re-enable coderef-in-stash optimization"
Reapply "op.c: re-enable coderef-in-stash optimization"