Skip to content

GH-115506: Improve handling of constants in tier two#124809

Closed
brandtbucher wants to merge 11 commits intopython:mainfrom
brandtbucher:tier-two-constants
Closed

GH-115506: Improve handling of constants in tier two#124809
brandtbucher wants to merge 11 commits intopython:mainfrom
brandtbucher:tier-two-constants

Conversation

@brandtbucher
Copy link
Member

@brandtbucher brandtbucher commented Sep 30, 2024

This adds a refs tuple to executor objects, which contains constants created during optimization of tier two traces. This isn't deduplicated at all, since not all of our "constants" are actually "constant", and arbitrary hashes/comparisons can open up a whole can of worms. If we want to go that route, we can probably re-use _PyCode_ConstantKey for known safe, immutable types, and compare everything else by identity.

This also updates some parts of the optimizer to improve the handling of known constants (such as adding peepholing for _POP_TOP_LOAD_CONST_INLINE_BORROW, _REPLACE_WITH_TRUE, and _COPY/_LOAD_FAST with known constant values).

Performance and memory are in the noise... perhaps a bit faster if you squint hard enough. But it's working: the stats show lots of instructions like _REPLACE_WITH_TRUE, _POP_TOP_LOAD_CONST_INLINE_BORROW, _LOAD_FAST, _COPY, and _BINARY_OP_ADD_INT being replaced with simpler instructions like _LOAD_CONST_INLINE_BORROW, _POP_TOP, and _LOAD_CONST_INLINE.

My next step will be experimenting with no-refcount variants of _COPY, _LOAD_FAST, _STORE_FAST, and _POP_TOP with known immortal values.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants