In perl.git, the branch optimize_return has been created <http://perl5.git.perl.org/perl.git/commitdiff/b5fbcd70fbf4a5f6000eb053873d73ee06d26913?hp=0000000000000000000000000000000000000000>
at b5fbcd70fbf4a5f6000eb053873d73ee06d26913 (commit) - Log ----------------------------------------------------------------- commit b5fbcd70fbf4a5f6000eb053873d73ee06d26913 Author: Matthew Horsfall <wolfs...@gmail.com> Date: Thu Dec 12 10:22:18 2013 -0500 Tests for RETURN/PUSHMARK optimisation M ext/B/t/optree_samples.t commit f4f7c8112fa6b08eb24f93b12dee6c7e2044a980 Author: Matthew Horsfall <wolfs...@gmail.com> Date: Wed Dec 11 18:28:21 2013 -0500 Optimise out PUSHMARK/RETURN if return is the last statement in a sub. This makes: sub baz { return $cat; } Behave like: sub baz { $cat; } Which is notably faster. Unpatched: ./perl -Ilib/ ~/stuff/bench.pl Benchmark: timing 40000000 iterations of normal, ret... normal: 3 wallclock secs ( 1.60 usr + 0.01 sys = 1.61 CPU) @ 24844720.50/s (n=40000000) ret: 3 wallclock secs ( 2.08 usr + 0.00 sys = 2.08 CPU) @ 19230769.23/s (n=40000000) Patched: ./perl -Ilib ~/stuff/bench.pl Benchmark: timing 40000000 iterations of aret, normal... normal: 2 wallclock secs ( 1.72 usr + 0.00 sys = 1.72 CPU) @ 23255813.95/s (n=40000000) ret: 2 wallclock secs ( 1.72 usr + 0.00 sys = 1.72 CPU) @ 23255813.95/s (n=40000000) The difference in OP trees can be seen here: Unpatched: $ perl -MO=Concise,baz -e 'sub baz { return $cat }' main::baz: 5 <1> leavesub[1 ref] K/REFC,1 ->(end) - <@> lineseq KP ->5 1 <;> nextstate(main 1 -e:1) v ->2 4 <@> return K ->5 2 <0> pushmark s ->3 - <1> ex-rv2sv sK/1 ->4 3 <#> gvsv[*cat] s ->4 -e syntax OK Patched: $ ./perl -Ilib -MO=Concise,baz -e 'sub baz { return $cat }' main::baz: 3 <1> leavesub[1 ref] K/REFC,1 ->(end) - <@> lineseq KP ->3 1 <;> nextstate(main 1 -e:1) v ->2 - <@> return K ->- - <0> pushmark s ->2 - <1> ex-rv2sv sK/1 ->- 2 <$> gvsv(*cat) s ->3 -e syntax OK M op.c M op.h ----------------------------------------------------------------------- -- Perl5 Master Repository