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-143421: Lazily allocate tracer code and opt buffers by Fidget-Spinner · Pull Request #143597 · python/cpython

Conversation

@Fidget-Spinner

@Fidget-Spinner Fidget-Spinner commented Jan 9, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

I verified on my system this restores the old performance.

  • Issue: JIT optimizer cleanups #143421

Sorry, something went wrong.

Uh oh!

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

cocolato reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@Fidget-Spinner
Lazily allocate tracer code and opt buffers
fbbac65
@Fidget-Spinner
Fidget-Spinner requested review from ZeroIntensity, ericsnowcurrently, markshannon and tomasr8 as code owners January 9, 2026 11:12
@bedevere-app bedevere-app Bot added the awaiting core review label Jan 9, 2026
@Fidget-Spinner Fidget-Spinner added the skip news label Jan 9, 2026
@Fidget-Spinner Fidget-Spinner changed the title gh-143536: Lazily allocate tracer code and opt buffers gh-143421: Lazily allocate tracer code and opt buffers Jan 9, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Jan 9, 2026
JIT optimizer cleanups #143421
Closed
@Fidget-Spinner Fidget-Spinner mentioned this pull request Jan 9, 2026
gh-143421: Move JitOptContext from stack allocation to per-thread heap allocation to avoid stack overflow. #143536
Merged
@cocolato

cocolato commented Jan 9, 2026

Copy link
Copy Markdown
Member

Should we remove the newly added pycore_optimizer_types.h?

All reactions

Sorry, something went wrong.

Uh oh!

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

corona10
corona10 approved these changes Jan 9, 2026
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Jan 9, 2026
@Fidget-Spinner

Fidget-Spinner commented Jan 9, 2026

Copy link
Copy Markdown
Member Author

Should we remove the newly added pycore_optimizer_types.h?

Let's keep it. It's a good refactor.

All reactions

Sorry, something went wrong.

Uh oh!

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

@Fidget-Spinner
Cut down locals and stack size
2354e78
@Fidget-Spinner
Fidget-Spinner merged commit b852236 into python:main Jan 9, 2026
62 checks passed

Uh oh!

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

@Fidget-Spinner
Fidget-Spinner deleted the lazily-allocate branch January 9, 2026 16:56
@bedevere-app bedevere-app Bot removed the awaiting merge label Jan 9, 2026
markshannon
markshannon reviewed Jan 9, 2026
View reviewed changes
Comment thread Include/internal/pycore_optimizer_types.h
// Holds locals, stack, locals, stack ... co_consts (in that order)
#define MAX_ABSTRACT_INTERP_SIZE 4096
// Holds locals, stack, locals, stack ... (in that order)
#define MAX_ABSTRACT_INTERP_SIZE 512

@markshannon markshannon Jan 9, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Sorry, something went wrong.

Uh oh!

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

All reactions

@Fidget-Spinner Fidget-Spinner Jan 9, 2026

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This number was picked arbitrarily by me back then when I first wrote this. I now realise it's overkill. We don't need 3 pages of memory just to store locals and stack. It's slow and wastes memory.

Sorry, something went wrong.

Uh oh!

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

All reactions
@markshannon

markshannon commented Jan 9, 2026

Copy link
Copy Markdown
Member

This makes no sense to me. How is allocating the necessary memory piecemeal faster than allocating it in a single chunk?

All reactions

Sorry, something went wrong.

Uh oh!

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

@Fidget-Spinner

Fidget-Spinner commented Jan 9, 2026

Copy link
Copy Markdown
Member Author

@markshannon no the problem was embedding it as a part of _PyThreadStateImpl, that caused a 100% slowdown of thread spawning time on the benchmark, which reflected in bench_thread_pool.

All reactions

Sorry, something went wrong.

Uh oh!

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

@Fidget-Spinner

Fidget-Spinner commented Jan 9, 2026

Copy link
Copy Markdown
Member Author

The benchmark doesn't run any work to use the JIT, instead it just measures thread startup overhead https://github.com/python/pyperformance/blob/main/pyperformance/data-files/benchmarks/bm_concurrent_imap/run_benchmark.py#L19

Embedding the two structs together in the _PyThreadStateImpl causes a massive slowdown.

All reactions

Sorry, something went wrong.

Uh oh!

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

@markshannon

markshannon commented Jan 9, 2026

Copy link
Copy Markdown
Member

It shouldn't be embedded, it should be heap allocated as one
#143536 (comment)

All reactions

Sorry, something went wrong.

Uh oh!

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

@Fidget-Spinner

Fidget-Spinner commented Jan 9, 2026

Copy link
Copy Markdown
Member Author

It shouldn't be embedded, it should be heap allocated as one #143536 (comment)

Ok let me just put a up a PR to do that.

markshannon reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

reidenong pushed a commit to reidenong/cpython that referenced this pull request Jan 12, 2026
@Fidget-Spinner @reidenong
pythongh-143421: Lazily allocate tracer code and opt buffers (pythonG…
ac9af52
…H-143597)
thunder-coding pushed a commit to thunder-coding/cpython that referenced this pull request Feb 15, 2026
@Fidget-Spinner @thunder-coding
pythongh-143421: Lazily allocate tracer code and opt buffers (pythonG…
bc68e75
…H-143597)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@markshannon markshannon markshannon left review comments
@corona10 corona10 corona10 approved these changes
@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently ericsnowcurrently is a code owner
@ZeroIntensity ZeroIntensity Awaiting requested review from ZeroIntensity ZeroIntensity is a code owner
@tomasr8 tomasr8 Awaiting requested review from tomasr8 tomasr8 is a code owner

Uh oh!

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

Assignees

No one assigned

Labels

skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

4 participants

@Fidget-Spinner @cocolato @markshannon @corona10
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.