Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Locale-Maketext CPAN distribution.

Report information
The Basics
Id: 48118
Status: resolved
Priority: 0/
Queue: Locale-Maketext

People
Owner: TODDR [...] cpan.org
Requestors: dmuey [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: 1.15_01



Subject: trivial change that makes _compile() 9% faster
Hello, According to my boss, his benchmarking found that this very minor and trivial change to _compile() benchmarked 9% faster.
Subject: _compile_speedup.patch
Index: Maketext.pm =================================================================== --- Maketext.pm (revision 37506) +++ Maketext.pm (working copy) @@ -510,16 +510,10 @@ # This big scary routine compiles an entry. # It returns either a coderef if there's brackety bits in this, or # otherwise a ref to a scalar. - - my $target = ref($_[0]) || $_[0]; - - my(@code); - my(@c) = (''); # "chunks" -- scratch. - my $call_count = 0; - my $big_pile = ''; + my ($target,$call_count,$big_pile,@c,@code) = ( (ref($_[0]) || $_[0]), 0, '', '' ); { - my $in_group = 0; # start out outside a group - my($m, @params); # scratch + # start out outside a group + my($in_group, $m, @params) = (0); # scratch while($_[1] =~ # Iterate over chunks. m/\G(
To make it easier to review and implement I've put all changes into a single small patch. This is a complete w/ Changelog, POD, tests, and version 1.13_85 -> 1.13_86
diff -ruN Locale-Maketext-1.13_85/ChangeLog Locale-Maketext-1.13_86/ChangeLog --- Locale-Maketext-1.13_85/ChangeLog 2009-07-30 13:51:44.000000000 -0500 +++ Locale-Maketext-1.13_86/ChangeLog 2009-07-30 14:10:43.000000000 -0500 @@ -1,5 +1,10 @@ Revision history for Perl suite Locale::Maketext +2009-08-04 Adriano Ferreira + * Development release 1.13_86 + + some speedup and efficiency tweaks (thanks Dan Muey) + 2009-08-03 Adriano Ferreira * Development release 1.13_85 diff -ruN Locale-Maketext-1.13_85/lib/Locale/Maketext.pm Locale-Maketext-1.13_86/lib/Locale/Maketext.pm --- Locale-Maketext-1.13_85/lib/Locale/Maketext.pm 2009-07-30 14:00:25.000000000 -0500 +++ Locale-Maketext-1.13_86/lib/Locale/Maketext.pm 2009-07-30 15:04:16.000000000 -0500 @@ -10,7 +10,7 @@ BEGIN { unless(defined &DEBUG) { *DEBUG = sub () {0} } } # define the constant 'DEBUG' at compile-time -$VERSION = '1.13_85'; +$VERSION = '1.13_86'; $VERSION = eval $VERSION; @ISA = (); @@ -132,8 +132,8 @@ $handle->{'failure_lex'} ||= {}; my $lex = $handle->{'failure_lex'}; - - my $value = $lex->{$phrase} ||= $handle->_compile($phrase); + # tr/X// is a very fast "does this string have this character" check, so we don't even call _compile if we know it will end up being a SCALAR ref + my $value = $lex->{$phrase} ||= ($phrase !~ tr/[// ? \"$phrase" : $handle->_compile($phrase)); # Dumbly copied from sub maketext: return ${$value} if ref($value) eq 'SCALAR'; @@ -211,11 +211,13 @@ # end $Onesided # Nonref means it's not yet compiled. Compile and replace. - if ($handle->{'use_external_lex_cache'}) { - $value = $handle->{'_external_lex_cache'}{$phrase} = $handle->_compile($value); + if ($handle->{'use_external_lex_cache'}) { + # tr/X// is a very fast "does this string have this character" check, so we don't even call _compile if we know it will end up being a SCALAR ref + $handle->{'_external_lex_cache'}{$phrase} = $value = ($value !~ tr/[// ? \"$value" : $handle->_compile($value)); } else { - $value = $h_r->{$phrase} = $handle->_compile($value); + # tr/X// is a very fast "does this string have this character" check, so we don't even call _compile if we know it will end up being a SCALAR ref + $h_r->{$phrase} = $value = ($value !~ tr/[// ? \"$value" : $handle->_compile($value)); } } last; @@ -225,11 +227,13 @@ elsif($phrase !~ m/^_/s and ($handle->{'use_external_lex_cache'} ? ( exists $handle->{'_external_lex_cache'}{'_AUTO'} ? $handle->{'_external_lex_cache'}{'_AUTO'} : $h_r->{'_AUTO'} ) : $h_r->{'_AUTO'})) { # it's an auto lex, and this is an autoable key! DEBUG and warn " Automaking \"$phrase\" into $h_r\n"; - if ($handle->{'use_external_lex_cache'}) { - $value = $handle->{'_external_lex_cache'}{$phrase} = $handle->_compile($phrase); + if ($handle->{'use_external_lex_cache'}) { + # tr/X// is a very fast "does this string have this character" check, so we don't even call _compile if we know it will end up being a SCALAR ref + $handle->{'_external_lex_cache'}{$phrase} = $value = ($phrase !~ tr/[// ? \"$phrase" : $handle->_compile($phrase)); } else { - $value = $h_r->{$phrase} = $handle->_compile($phrase); + # tr/X// is a very fast "does this string have this character" check, so we don't even call _compile if we know it will end up being a SCALAR ref + $h_r->{$phrase} = $value = ($phrase !~ tr/[// ? \"$phrase" : $handle->_compile($phrase)); } last; } @@ -505,16 +509,14 @@ # This big scary routine compiles an entry. # It returns either a coderef if there's brackety bits in this, or # otherwise a ref to a scalar. - - my $target = ref($_[0]) || $_[0]; - - my(@code); - my(@c) = (''); # "chunks" -- scratch. - my $call_count = 0; - my $big_pile = ''; + + # tr/X// is a very fast "does this string have this character" check, so we don't need to continue if we know it will end up being a SCALAR ref + return \"$_[1]" if $_[1] !~ tr/[//; + + my ($target,$call_count,$big_pile,@c,@code) = ( (ref($_[0]) || $_[0]), 0, '', '' ); { - my $in_group = 0; # start out outside a group - my($m, @params); # scratch + # start out outside a group + my($in_group, $m, @params) = (0); # scratch while($_[1] =~ # Iterate over chunks. m/\G(
On Thu Jul 30 16:09:44 2009, DMUEY wrote: Show quoted text
> To make it easier to review and implement I've put all changes into a > single small patch. > > This is a complete w/ Changelog, POD, tests, and version 1.13_85 ->
1.13_86 A ready-to-upload-via-pause tarball of said patch
Download Locale-Maketext-1.13_86.tar.gz
application/x-gzip 48.4k

Message body not shown because it is not plain text.

the changes may seem trivial but when you are doing 400-1000 maketext()'s then tiny ops add up quickly :)
From: toddr [...] null.net
forked perl blead on github - http://github.com/toddr/perl/tree/toddr/maketext-locale will be submitting to P5P post 5.12.0 freeze per advice from jesse Commit: http://github.com/toddr/perl/commit/7d99e4db6aefb66a4a64764b6ffcf6 d4d8bfdc21
Accepted by p5p commit 152eae845915a3a33260ad109ad3888c8894d666 Author: Todd Rinaldo <toddr@cpan.org> Date: Tue Sep 28 11:13:33 2010 -0700 [perl #76674] Locale::Maketext: speed and efficiency tweaks Check string to compile for chars ~][ and return \"$string" if not found. This is a 250% speed improvement on strings which don't require compile and only a ~2% hit if they did need compiling. Remove \G since everything is being captured it has no value. This means we don't have to worry about seting pos $string_to_compile = 0 to prevent the previous regex from affecting this one. There is a negligible speed improvement removing the \G
1.15_02 is the RC for 1.16. No issues so far. closing ticket.