summaryrefslogtreecommitdiff
path: root/t/perf
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2016-11-15 08:27:48 +0000
committerDavid Mitchell <davem@iabyn.com>2016-11-16 09:54:33 +0000
commita0833292cfd2e6c3e7390b655122d7e033b70793 (patch)
tree725028ef67a9fb9382e49498a75aa79b6096b700 /t/perf
parent90303eefab11f53890ba7378a38c90ca58b20072 (diff)
downloadperl-a0833292cfd2e6c3e7390b655122d7e033b70793.tar.gz
optimise $ref1 = $ref2 better
When assigning to a ref, the old referent is mortalised if its refcount is 1, to avoid a premature free on things like $r = $$r or $r = $r->[0]. For the shortcut case where $ref1 and $ref2 are simple refs (no magic etc) it's possible to do the assign then SvREFCNT_dec() the old value without having to mortalise it. Which is faster. Even when it doesn't have to be mortalised (RC > 1) this commit makes it slightly faster as it no longer calls sv_unref_flags(). Conversely, this commit also makes the short-cut integer assign code path infinitesimally slower.
Diffstat (limited to 't/perf')
-rw-r--r--t/perf/benchmarks10
1 files changed, 10 insertions, 0 deletions
diff --git a/t/perf/benchmarks b/t/perf/benchmarks
index 6dfe442d3c..8306b1fcff 100644
--- a/t/perf/benchmarks
+++ b/t/perf/benchmarks
@@ -891,6 +891,16 @@
setup => 'my $x = 1;',
code => '$x = "abc"',
},
+ 'expr::sassign::lex_rv' => {
+ desc => 'lexical $ref1 = $ref2;',
+ setup => 'my $r1 = []; my $r = $r1;',
+ code => '$r = $r1;',
+ },
+ 'expr::sassign::lex_rv1' => {
+ desc => 'lexical $ref1 = $ref2; where $$ref1 gets freed',
+ setup => 'my $r1 = []; my $r',
+ code => '$r = []; $r = $r1;',
+ },