Make all operations leave a value on the stack for easier specialization. #241
markshannon
started this conversation in
Ideas
Replies: 2 comments
-
Are you sure it's a perf gain?
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Am I sure? No:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Most operation produce a value, and thus leave a value on the stack.
This has the nice property that the operation can be substituted with a call which has the same effect.
For example, we already specialize
BINARY_SUBSCR
withBINARY_SUBSCR_GETITEM
for instances of classes that implement__getitem__
in Python.BINARY_SUBSCR_GETITEM
pushes a frame and then enters the__getitem__
function without having to make any C calls.We can do the same for
LOAD_ATTR
, and any calls (it makes sense to substitute one callable for another in some circumstances).However, we cannot do easily do this for
__setitem__
or__setattr__
.By changing
STORE_SUBSCR
andSTORE_ATTR
to leave a value on the stack, we can freely substitute them with a call.Obviously changing
STORE_SUBSCR
to pushNone
and then following it withPOP_TOP
is not very efficient if done naively.However, it we guarantee that
STORE_SUBSCR
andSTORE_ATTR
are always followed byPOP_TOP
, we can simply change them to bumpnext_instr
by one and skip the following instruction at no cost.The question is: does the performance gain and simplification of the specialized forms outweigh the small cost of the extra 2 bytes per store?
I expect that it will, but we will need to experiment.
NOTE:
We can do the specialization without changing
STORE_SUBSCR
, but it requires the specialized form to push an extra frame just to execute an instruction to discard the top of the stack and pop the current frame: aRETURN_VOID
instruction.Beta Was this translation helpful? Give feedback.
All reactions