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_SUBSCRwithBINARY_SUBSCR_GETITEMfor instances of classes that implement__getitem__in Python.BINARY_SUBSCR_GETITEMpushes 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_SUBSCRandSTORE_ATTRto leave a value on the stack, we can freely substitute them with a call.Obviously changing
STORE_SUBSCRto pushNoneand then following it withPOP_TOPis not very efficient if done naively.However, it we guarantee that
STORE_SUBSCRandSTORE_ATTRare always followed byPOP_TOP, we can simply change them to bumpnext_instrby 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_VOIDinstruction.Beta Was this translation helpful? Give feedback.
All reactions