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
Undocumented whether string constants are efficient #7853
Comments
From porton@ex-code.comCreated by porton@ex-code.comIt is unclear from the constant(3pm) manpage whether string Well, anyway they should be made efficient if they are not. # Example of a string constant Perl Info
|
From @schwernOn Sun, Mar 27, 2005 at 01:51:26PM -0000, Victor Porton,,, wrote:
constant.pm makes it pretty clear about the mechanics... TECHNICAL NOTES The long string will be inlined straight into the code, so the question Well, let's do some testing. First we slurp in a big list of words and $ perl5.8.6 -wle 'BEGIN { open WORDS, "/usr/dict/words" or die $!; } use constant STR => join "", <WORDS>; sleep 99; print STR' schwern 9760 0.0 4.9 48764 38856 std S 11:40AM 0:00.90 perl5.8.6 -wle BEGIN { open WORDS, "/usr/dict/words" or die $!; Then we mention it twice. $ perl5.8.6 -wle 'BEGIN { open WORDS, "/usr/dict/words" or die $!; } use constant STR => join "", <WORDS>; sleep 99; print STR; print STR' & schwern 9766 0.4 5.3 51196 41288 std S 11:41AM 0:00.90 perl5.8.6 -wle BEGIN { open WORDS, "/usr/dict/words" or die $!; Three times... schwern 9772 0.0 5.6 53628 43720 std S 11:42AM 0:00.99 perl5.8.6 -wle BEGIN { open WORDS, "/usr/dict/words" or die $!; Its going up by 2432K each time which is just how long STR happens to be. $ perl5.8.6 -wle 'BEGIN { open WORDS, "/usr/dict/words" or die $!; } use constant STR => join "", <WORDS>; print length(STR) / 1024;' So the answer is that long, repeated, inlined strings don't have any special If you want a string which cannot be changed and is memory efficient you can our $STR; *STR = \"Some string"; Whether or not this should be documented in constant.pm... probably just |
The RT System itself - Status changed from 'new' to 'open' |
From @demerphqOn Sun, 27 Mar 2005 11:49:47 -0800, Michael G Schwern <schwern@pobox.com> wrote:
I know why you are adding the caveat, but really is it necessary in Im mostly curious as in the current state of the docs I think the Cheers, -- |
From @schwernOn Sun, Mar 27, 2005 at 10:15:39PM +0200, demerphq wrote:
I don't believe its ever changed in the past but that's not much of an Given that we (try) to share hash keys and Arthur's off somewhere working on It might make sense to share all constant strings, integers, etc... rather
Beside the point of if its a good idea not not to share strings, its an So its worth an extra 5 words to avoid mortgaging the future. |
From @ysthOn Sun, Mar 27, 2005 at 01:32:11PM -0800, Michael G Schwern wrote:
One complicating issue with this is that even constants are "owned" by $ perl -MScalar::Util=weaken -wle'$x=eval"sub{\\1}"; weaken($y=&$x); print "before:$y"; undef $x; print "after:$y"' |
From @schwernOn Sun, Mar 27, 2005 at 07:07:45PM -0800, Yitzchak Scott-Thoennes wrote:
"This" being whether or not sharing constants is viable as opposed to the
What I was thinking is a situation where the SV structs are distinct but the So instead of... $ perl -MDevel::Peek -wle 'my $foo = "foo"; my $bar = "foo"; print Dump $foo; print Dump $bar' SV = PV(0x8014a8) at 0x809fc0 It would be SV = PV(0x801460) at 0x801234 SV = PV(0x8014a8) at 0x809fc0 With sufficient cleverness to deallocate the string when the last SV Again, whether the extra management would be worth it... dunno. A first |
@rgs - Status changed from 'open' to 'resolved' |
From @AbigailOn Sun, Mar 27, 2005 at 11:49:47AM -0800, Michael G Schwern wrote:
Alternatively, one can use the less cryptic: use Readonly; Abigail |
Migrated from rt.perl.org#34584 (status was 'resolved')
Searchable as RT34584$
The text was updated successfully, but these errors were encountered: