In perl.git, the branch nicholas/build-trim has been updated <http://perl5.git.perl.org/perl.git/commitdiff/3abe4a15faad3c4b0fa99734b3c896de83346dae?hp=f6f843fb9677f20d29f6881ae85b2825c42f7b8e>
- Log ----------------------------------------------------------------- commit 3abe4a15faad3c4b0fa99734b3c896de83346dae Author: Nicholas Clark <[email protected]> Date: Mon May 7 09:58:13 2012 +0200 In mktables, lazily compute the 'standard_form' for Ranges. Instead of calculating the standard form up front, calculate it only when needed and cache the result. There are 368676 non-special objects, but the standard form is only requested for 22047 of them. For the systems I tested on, this reduces RAM and CPU usage by about 10% on Linux, and 6% on FreeBSD. This is more significant than it may first seem, because mktables is the largest RAM user of anything run during the build process, so this reduces the build process peak RAM requirement. ----------------------------------------------------------------------- Summary of changes: lib/unicore/mktables | 16 +++++++++------- 1 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/unicore/mktables b/lib/unicore/mktables index 7eba4f9..3c453e4 100644 --- a/lib/unicore/mktables +++ b/lib/unicore/mktables @@ -2840,10 +2840,6 @@ sub trace { return main::trace(@_); } Carp::carp_extra_args(\%args) if main::DEBUG && %args; - if (! $type{$addr}) { - $standard_form{$addr} = main::standardize($value); - } - return $self; } @@ -2872,8 +2868,11 @@ sub trace { return main::trace(@_); } } sub standard_form { - # The standard form is the value itself if the standard form is - # undefined (that is if the value is special) + # Calculate the standard form only if needed, and cache the result. + # The standard form is the value itself if the type is special. + # This represents a considerable CPU and memory saving - at the time + # of writing there are 368676 non-special objects, but the standard + # form is only requested for 22047 of them - ie about 6%. my $self = shift; Carp::carp_extra_args(\@_) if main::DEBUG && @_; @@ -2881,7 +2880,10 @@ sub trace { return main::trace(@_); } my $addr = do { no overloading; pack 'J', $self; }; return $standard_form{$addr} if defined $standard_form{$addr}; - return $value{$addr}; + + my $value = $value{$addr}; + return $value if $type{$addr}; + return $standard_form{$addr} = main::standardize($value); } sub dump { -- Perl5 Master Repository
