GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GH-135379: Top of stack caching for the JIT. by markshannon · Pull Request #135465 · python/cpython

GH-135379: Top of stack caching for the JIT. #135465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
markshannon merged 3 commits into python:main from faster-cpython:tier-2-tos-caching
Dec 11, 2025

Uh oh!

There was an error while loading. Please reload this page.

Merged

GH-135379: Top of stack caching for the JIT. #135465

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
3 commits
Select commit Hold shift + click to select a range
4fec38d
Tier 2 TOS caching
markshannon Dec 5, 2025
4b24c15
Merge branch 'main' into tier-2-tos-caching
markshannon Dec 10, 2025
a54eca7
Merge branch 'main' into tier-2-tos-caching
markshannon Dec 11, 2025
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

2 changes: 1 addition & 1 deletion 2 Include/cpython/pystats.h
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# error "this header file must not be included directly"
#endif

#define PYSTATS_MAX_UOP_ID 1024
#define PYSTATS_MAX_UOP_ID 2000

#define SPECIALIZATION_FAILURE_KINDS 60

Expand Down
5 changes: 4 additions & 1 deletion 5 Include/internal/pycore_jit.h
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ extern "C" {

#ifdef _Py_JIT

typedef _Py_CODEUNIT *(*jit_func)(_PyInterpreterFrame *frame, _PyStackRef *stack_pointer, PyThreadState *tstate);
typedef _Py_CODEUNIT *(*jit_func)(
_PyInterpreterFrame *frame, _PyStackRef *stack_pointer, PyThreadState *tstate,
_PyStackRef _tos_cache0, _PyStackRef _tos_cache1, _PyStackRef _tos_cache2
);

int _PyJIT_Compile(_PyExecutorObject *executor, const _PyUOpInstruction *trace, size_t length);
void _PyJIT_Free(_PyExecutorObject *executor);
Expand Down
52 changes: 27 additions & 25 deletions 52 Include/internal/pycore_opcode_metadata.h
Show comments
View file
Open in desktop

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

22 changes: 6 additions & 16 deletions 22 Include/internal/pycore_optimizer.h
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@ typedef struct _PyExecutorLinkListNode {
typedef struct {
uint8_t opcode;
uint8_t oparg;
uint8_t valid:1;
uint8_t linked:1;
uint8_t chain_depth:6; // Must be big enough for MAX_CHAIN_DEPTH - 1.
uint8_t valid;
uint8_t linked;
uint8_t chain_depth; // Must be big enough for MAX_CHAIN_DEPTH - 1.
bool warm;
int index; // Index of ENTER_EXECUTOR (if code isn't NULL, below).
int32_t index; // Index of ENTER_EXECUTOR (if code isn't NULL, below).
_PyBloomFilter bloom;
_PyExecutorLinkListNode links;
PyCodeObject *code; // Weak (NULL if no corresponding ENTER_EXECUTOR).
} _PyVMData;

typedef struct _PyExitData {
uint32_t target;
uint16_t index:14;
uint16_t index:12;
uint16_t stack_cache:2;
uint16_t is_dynamic:1;
uint16_t is_control_flow:1;
_Py_BackoffCounter temperature;
Expand Down Expand Up @@ -344,17 +345,6 @@ extern _PyExecutorObject *_PyExecutor_GetColdDynamicExecutor(void);

PyAPI_FUNC(void) _PyExecutor_ClearExit(_PyExitData *exit);

static inline int is_terminator(const _PyUOpInstruction *uop)
{
int opcode = uop->opcode;
return (
opcode == _EXIT_TRACE ||
opcode == _DEOPT ||
opcode == _JUMP_TO_TOP ||
opcode == _DYNAMIC_EXIT
);
}

extern void _PyExecutor_Free(_PyExecutorObject *self);

PyAPI_FUNC(int) _PyDumpExecutors(FILE *out);
Expand Down
17 changes: 17 additions & 0 deletions 17 Include/internal/pycore_stackref.h
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ static const _PyStackRef PyStackRef_ERROR = { .index = (1 << Py_TAGGED_SHIFT) };

#define INITIAL_STACKREF_INDEX (5 << Py_TAGGED_SHIFT)

#define PyStackRef_ZERO_BITS PyStackRef_NULL

static inline _PyStackRef
PyStackRef_Wrap(void *ptr)
{
Expand Down Expand Up @@ -369,6 +371,10 @@ PyStackRef_IsNullOrInt(_PyStackRef ref);

static const _PyStackRef PyStackRef_ERROR = { .bits = Py_TAG_INVALID };

/* For use in the JIT to clear an unused value.
* PyStackRef_ZERO_BITS has no meaning and should not be used other than by the JIT. */
static const _PyStackRef PyStackRef_ZERO_BITS = { .bits = 0 };

/* Wrap a pointer in a stack ref.
* The resulting stack reference is not safe and should only be used
* in the interpreter to pass values from one uop to another.
Expand Down Expand Up @@ -922,6 +928,17 @@ _PyThreadState_PopCStackRef(PyThreadState *tstate, _PyCStackRef *ref)
PyStackRef_XCLOSE(ref->ref);
}

static inline _PyStackRef
_PyThreadState_PopCStackRefSteal(PyThreadState *tstate, _PyCStackRef *ref)
{
#ifdef Py_GIL_DISABLED
_PyThreadStateImpl *tstate_impl = (_PyThreadStateImpl *)tstate;
assert(tstate_impl->c_stack_refs == ref);
tstate_impl->c_stack_refs = ref->next;
#endif
return ref->ref;
}

#ifdef Py_GIL_DISABLED

static inline int
Expand Down
4 changes: 2 additions & 2 deletions 4 Include/internal/pycore_uop.h
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ typedef struct _PyUOpInstruction{
// This is the length of the trace we translate initially.
#ifdef Py_DEBUG
// With asserts, the stencils are a lot larger
#define UOP_MAX_TRACE_LENGTH 1000
#define UOP_MAX_TRACE_LENGTH 2000
#else
#define UOP_MAX_TRACE_LENGTH 3000
#define UOP_MAX_TRACE_LENGTH 5000
#endif
#define UOP_BUFFER_SIZE (UOP_MAX_TRACE_LENGTH * sizeof(_PyUOpInstruction))

Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.