FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-131798: JIT inline function addresses of builtin methods by kumaraditya303 · Pull Request #146906 · python/cpython · GitHub

Repository navigation

gh-131798: JIT inline function addresses of builtin methods - #146906

Merged
kumaraditya303 merged 20 commits into
python:mainfrom
kumaraditya303:jit-inline-funcptr
Apr 4, 2026
Merged

kumaraditya303 merged 20 commits into
python:mainfrom
kumaraditya303:jit-inline-funcptr

Conversation

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

Copy link
Copy Markdown
Contributor

Fidget-Spinner commented Mar 31, 2026 •
edited
Loading

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!

Fidget-Spinner commented Mar 31, 2026 •
edited
Loading

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.

Fidget-Spinner commented Apr 3, 2026 •
edited
Loading

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.

kumaraditya303 commented Apr 3, 2026 •
edited
Loading

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%

Fidget-Spinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

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.

Comment thread Python/optimizer_bytecodes.c Outdated

Copy link
Copy Markdown
Member

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.

kumaraditya303 merged commit 7e275d4 into python:main Apr 4, 2026
73 of 74 checks passed
kumaraditya303 deleted the jit-inline-funcptr branch April 4, 2026 03:42
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL