Optimization: Remove needless list/pushmark pairs from the OP execution
authorSteffen Mueller <smueller@cpan.org>
Sat, 22 Feb 2014 09:08:25 +0000 (10:08 +0100)
committerSteffen Mueller <smueller@cpan.org>
Wed, 26 Feb 2014 20:27:57 +0000 (21:27 +0100)
commit7d3c8a6837b55fff0e6294ebf8c94a1601367c76
treea73bc7c98cf940228a9be15c13c3521a13b865c9
parent11ee9dd668c24ff655cfec47610c8939e74a8506
Optimization: Remove needless list/pushmark pairs from the OP execution

This is an optimization for OP trees that involve list OPs in list
context. In list context, the list OP's first child, a pushmark, will do
what its name claims and push a mark to the mark stack, indicating the
start of a list of parameters to another OP. Then the list's other
child OPs will do their stack pushing. Finally, the list OP will be
executed and do nothing but undo what the pushmark has done. This is
because the main effect of the list OP only really kicks in if it's
not in array context (actually, it should probably only kick in if
it's in scalar context, but I don't know of any valid examples of
list OPs in void contexts).

This optimization is quite a measurable speed-up for array or hash
slicing and some other situations. Another (contrived) example is
that (1,2,(3,4)) now actually is the same, performance-wise as
(1,2,3,4), albeit that's rarely relevant.

The price to pay for this is a slightly convoluted (by standards other
than the perl core) bit of optimization logic that has to do minor
look-ahead on certain OPs in the peephole optimizer.

A number of tests failed after the first attack on this problem. The
failures were in two categories:

a) Tests that are sensitive to details of the OP tree structure and did
verbatim text comparisons of B::Concise output (ouch). These are just
patched according to the new red in this commit.

b) Test that validly failed because certain conditions in op.c were
expecting OP_LISTs where there are now OP_NULLs (with op_targ=OP_LIST).
For these, the respective conditions in op.c were adjusted.

The change includes modifying B::Deparse to handle the new OP tree
structure in the face of nulled OP_LISTs.
embed.fnc
embed.h
ext/B/t/f_map.t
ext/B/t/optree_samples.t
lib/B/Deparse.pm
op.c
proto.h