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-131798: JIT inline function addresses of builtin methods by kumaraditya303 · Pull Request #146906 · python/cpython

Conversation

@kumaraditya303

@kumaraditya303 kumaraditya303 commented Mar 31, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor
  • Issue: Better uop coverage in the JIT optimizer #131798

Sorry, something went wrong.

Uh oh!

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

All reactions
kumaraditya303 added 3 commits March 26, 2026 23:02
@kumaraditya303
function inline address
e9f92ec
@kumaraditya303
cleanup
ab8ae79
@kumaraditya303
Merge branch 'main' of https://github.com/python/cpython into jit-inl…
27e9def
…ine-funcptr
@kumaraditya303 kumaraditya303 added the skip news label Mar 31, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Mar 31, 2026
Better uop coverage in the JIT optimizer #131798
Open
kumaraditya303 added 2 commits March 31, 2026 17:43
@kumaraditya303
add tests
301060b
@kumaraditya303
fix fpcasts
e8fac3f
@kumaraditya303 kumaraditya303 mentioned this pull request Mar 31, 2026
JIT arm64 relocations does not handles large addresses #147805
Closed
kumaraditya303 added 2 commits March 31, 2026 20:56
@kumaraditya303
add fix suggested by Claude
ed50677
@kumaraditya303
another fix
c3e35f2
@Fidget-Spinner

Fidget-Spinner commented Mar 31, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

Edit: I might be wrong on the following, so please ignore the rest.

Really sorry I just realised this optimization may not be sound:

The builtin call specializations only check for that the builtin tp flags match, I don't think they check for tp_version_tag and such. So we can have a method that changes its tp_slots under our feet.

Sorry for taking up your time!

All reactions

Sorry, something went wrong.

Uh oh!

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

@Fidget-Spinner

Fidget-Spinner commented Mar 31, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

The rewriting that we discussed might still pay off though (rewriting {}.get() to a custom uop for example).

That should also be sound, provided we have the correct guards.

All reactions

Sorry, something went wrong.

Uh oh!

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

@Fidget-Spinner

Fidget-Spinner commented Apr 3, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

I think this is safe: let me explain why:

  1. PyMethodDescrObjects are immutable (as Kumar pointed out).
  2. type version tags are unique (unless they overflow, which is pretty unlikely as they have limits now).
  3. _GUARD_TYPE_VERSION and the type watcher later implies the type and thus method transitively later on.
    TLDR: This is safe on the invariant that LOAD_ATTR guards itself, and all known information is sourced from there to optimize the calls.
All reactions

Sorry, something went wrong.

Uh oh!

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

kumaraditya303 added 8 commits April 3, 2026 10:18
@kumaraditya303
Merge branch 'main' into jit-inline-funcptr
eb14e9b
@kumaraditya303
also fix x86-64
0a15b1c
@kumaraditya303
Merge branch 'jit-inline-funcptr' of https://github.com/kumaraditya30…
0162735
…3/cpython into jit-inline-funcptr
@kumaraditya303
Revert "also fix x86-64"
ce1183a
This reverts commit 0a15b1c.
@kumaraditya303
fix lint
fe3fcaf
@kumaraditya303
also fix x86-64
a30fcb8
@kumaraditya303
add workaround
43322c1
@kumaraditya303
mark it no inline
e10de14
@kumaraditya303

kumaraditya303 commented Apr 3, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

Microbenchmark results of calling bunch of methods on each type:

Type this branch main branch speedup
list 29,186 31,082 +6.5%
dict 18,244 18,761 +2.8%
set 9,152 9,681 +5.8%
str 18,185 18,922 +4.1%
deque 19,127 21,072 +10.2%
All reactions

Sorry, something went wrong.

Uh oh!

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

kumaraditya303 added 2 commits April 3, 2026 18:03
@kumaraditya303
Merge branch 'main' of https://github.com/python/cpython into jit-inl…
c0d63f6
…ine-funcptr
@kumaraditya303
wip
bc54b9e
@kumaraditya303
kumaraditya303 marked this pull request as ready for review April 3, 2026 12:57
@kumaraditya303
kumaraditya303 requested review from Fidget-Spinner, markshannon, savannahostrowski and tomasr8 as code owners April 3, 2026 12:57
@bedevere-app bedevere-app Bot added the awaiting core review label Apr 3, 2026
@kumaraditya303
remove _PyCallMethodDescriptorO_StackRef
14c0b8f
Fidget-Spinner
Fidget-Spinner approved these changes Apr 3, 2026
View reviewed changes

@Fidget-Spinner Fidget-Spinner left a comment

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.

Very impressive. Hopefully the site failure get fixed soon. Btw, could you please update your comment above with the final benchmark results on the current commit?

Also, from my understanding talking with Kumar, the speedup comes from removing 1 null check, and 2 dependent loads. Perhaps more importantly, the dependent loads likely then allow the CPU to prefetch the call directly, which is a pretty good speedup.

Sorry, something went wrong.

Uh oh!

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

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Apr 3, 2026
@kumaraditya303

kumaraditya303 commented Apr 3, 2026

Copy link
Copy Markdown
Contributor Author

Btw, could you please update your comment above with the final benchmark results on the current commit?

The numbers are very similar and within margin of error so keeping the existing result.

Fidget-Spinner 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.

Fidget-Spinner
Fidget-Spinner reviewed Apr 3, 2026
View reviewed changes
Comment thread Python/optimizer_bytecodes.c Resolved

Uh oh!

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

@kumaraditya303
fix is null bug
e4a2fff
@Fidget-Spinner

Fidget-Spinner commented Apr 3, 2026

Copy link
Copy Markdown
Member

Seems like a slight win on macOS, and a slight loss on x86-64 https://github.com/facebookexperimental/free-threading-benchmarking/tree/main/results/bm-20260403-3.15.0a7+-e4a2fff-JIT

All reactions

Sorry, something went wrong.

Uh oh!

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

@kumaraditya303

kumaraditya303 commented Apr 4, 2026

Copy link
Copy Markdown
Contributor Author

Seems like a slight win on macOS, and a slight loss on x86-64 https://github.com/facebookexperimental/free-threading-benchmarking/tree/main/results/bm-20260403-3.15.0a7+-e4a2fff-JIT

I think the benchmark runner is too noisy, for example the gc_traversal benchmark is 8% slower on linux but should be unaffected by this PR.

All reactions

Sorry, something went wrong.

Uh oh!

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

@kumaraditya303
-
7d7f72e
@kumaraditya303
kumaraditya303 merged commit 7e275d4 into python:main Apr 4, 2026
73 of 74 checks passed

Uh oh!

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

@bedevere-app bedevere-app Bot removed the awaiting merge label Apr 4, 2026
@kumaraditya303
kumaraditya303 deleted the jit-inline-funcptr branch April 4, 2026 03:42
@kumaraditya303 kumaraditya303 added the topic-JIT label Apr 4, 2026
@pablogsal pablogsal mentioned this pull request Apr 4, 2026
gh-130273: Fix traceback color output with unicode characters #142529
Merged
ljfp pushed a commit to ljfp/cpython that referenced this pull request Apr 25, 2026
@kumaraditya303 @ljfp
pythongh-131798: JIT inline function addresses of builtin methods (py…
5323f89
…thon#146906)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Fidget-Spinner Fidget-Spinner Fidget-Spinner approved these changes
@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner
@tomasr8 tomasr8 Awaiting requested review from tomasr8 tomasr8 is a code owner
@savannahostrowski savannahostrowski Awaiting requested review from savannahostrowski

Uh oh!

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

Assignees

No one assigned

Labels

skip news topic-JIT

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.

2 participants

@kumaraditya303 @Fidget-Spinner
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.