Closed
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-JITtype-featureA feature request or enhancement
Description
Feature or enhancement
Proposal:
Currently the JIT uop buffer modifies uops traces in place.
I think we should make it add to a new buffer. Having modifications be in-place is making our code messy and full of special cases.
So
REPLACE_OP(this_instr, ...)
should become
ADD_OP(ctx, ...)
in optimizer_bytecodes.c,
Also, the default generated case of optimizer_bytecodes.c should be to ADD_OP(pc, ...)
This is also blocking optimization in #143414, as ocassionally we need to insert extra guards to check the uniqueness of an object for example.
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Linked PRs
Reacted by Tomas R.
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-JITtype-featureA feature request or enhancement
Activity
markshannon commentedon Jan 5, 2026
I agree, but let's refactor the JIT structs to be heap allocated first.
Fidget-Spinner commentedon Jan 6, 2026
Assigning this to @cocolato
[-]Make the JIT optimizer buffer add to a new buffer, not in-place[/-][+] JIT optimizer cleanups[/+]gh-143421: Move `JitOptContext` from stack allocation to per-thread h…
Revert "pythongh-143421: Move `JitOptContext` from stack allocation t…
gh-143421: Lazily allocate tracer code and opt buffers (GH-143597)
gh-143421: Allocate all JIT state in one go (GH-143626)
cocolato commentedon Jan 10, 2026
How should we handle the following case? It appears that we cannot simply use
ADD_OPas a substitute. Perhaps we still need aREPLACE_OPto handle the new buffer.cpython/Python/optimizer_bytecodes.c
Line 1512 in e7f5ffa
cpython/Python/optimizer_bytecodes.c
Line 1024 in e7f5ffa
Fidget-Spinner commentedon Jan 10, 2026
@cocolato make REPLACE_OP operate on the new buffer instead of the old one. Ideally you should have two buffers. An old buffer containing the current uops, and a new buffer, containing the uops being written.
If the optimizer stops early, you can just insert an _EXIT_TRACE at that location in the new buffer.
pythongh-143421: Move `JitOptContext` from stack allocation to per-th…
pythongh-143421: Lazily allocate tracer code and opt buffers (pythonG…
pythongh-143421: Allocate all JIT state in one go (pythonGH-143626)
gh-143421: Use new buffer to save optimized uops (GH-143682)
pythongh-143421: Move `JitOptContext` from stack allocation to per-th…
pythongh-143421: Lazily allocate tracer code and opt buffers (pythonG…
pythongh-143421: Allocate all JIT state in one go (pythonGH-143626)
pythongh-143421: Use new buffer to save optimized uops (pythonGH-143682)