summaryrefslogtreecommitdiff
path: root/lib/unicore
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2012-06-02 16:32:44 +0100
committerKarl Williamson <public@khwilliamson.com>2012-06-02 10:12:46 -0600
commitc292d35a225572156ccde6f3a812f532f4347fad (patch)
treea58e0e0aece37f78ea07fc9cb50f2b383d28fe64 /lib/unicore
parent6fca57a162544ba8c19981fe8c8c0f7ec24dd1d7 (diff)
downloadperl-c292d35a225572156ccde6f3a812f532f4347fad.tar.gz
mktables memory reduction
Does the attached patch make sense? It lowers RAM and CPU usage by about 10% on Linux, and 6% on FreeBSD. Nicholas Clark >From fe46bd796c282f6a6e4793afaf847e04d3be3524 Mon Sep 17 00:00:00 2001 From: Nicholas Clark <nick@ccl4.org> Date: Mon, 7 May 2012 09:58:13 +0200 Subject: [PATCH] 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.
Diffstat (limited to 'lib/unicore')
-rw-r--r--lib/unicore/mktables16
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/unicore/mktables b/lib/unicore/mktables
index def260aa12..559c519639 100644
--- a/lib/unicore/mktables
+++ b/lib/unicore/mktables
@@ -2921,10 +2921,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;
}
@@ -2954,8 +2950,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 && @_;
@@ -2963,7 +2962,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 {