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 — Make the specializing interpreter thread-safe in `--disable-gil` builds · Issue #115999 · python/cpython

Make the specializing interpreter thread-safe in --disable-gil builds #115999

New issue
Copy link
New issue
Copy link
Closed
Closed
Make the specializing interpreter thread-safe in --disable-gil builds#115999
Copy link
Assignees
mpage
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-free-threadingtype-featureA feature request or enhancementA feature request or enhancement

Description

@swtaarrs
swtaarrs
opened on Feb 27, 2024
Issue body actions

Feature or enhancement

Proposal:

In free-threaded builds, the specializing adaptive interpreter needs to be made thread-safe. We should start with a small PR to simply disable it in free-threaded builds, which will be correct but will incur a performance penalty. Then we can work out how to properly support specialization in a free-threaded build.

These two commits from Sam's nogil-3.12 branch can serve as inspiration:

  1. specialize: make specialization thread-safe
  2. specialize: optimize for single-threaded programs

There are two primary concerns to balance while implementing this functionality on main:

  1. Runtime overhead: There should be no performance impact on normal builds, and minimal performance impact on single-threaded code running in free-threaded builds.
  2. Reducing code duplication/divergence: We should come up with a design that is minimally disruptive to ongoing work on the specializing interpreter. It should be easy for other devs to keep the free-threaded build working without having to know too much about it.

Has this already been discussed elsewhere?

I have already discussed this feature proposal on Discourse

Links to previous discussion of this feature:

  • https://peps.python.org/pep-0703/
  • PEP 703 -- Making the Global Interpreter Lock Optional in CPython #108219

Specialization Families

- [x] BINARY_OP
- [x] BINARY_SUBSCR - @corona10
- [x] CALL - @mpage
- [x] CALL_KW - @mpage
- [x] COMPARE_OP - @Yhg1s
- [x] CONTAINS_OP - @corona10
- [x] FOR_ITER - @Yhg1s
- [x] LOAD_ATTR - @mpage
- [x] LOAD_CONST
- [x] LOAD_GLOBAL - @mpage
- [x] LOAD_SUPER_ATTR - @nascheme
- [x] RESUME
- [x] SEND - @nascheme
- [x] STORE_ATTR - -@nascheme
- [x] STORE_SUBSCR - @colesbury
- [x] TO_BOOL - @corona10
- [x] UNPACK_SEQUENCE - @Eclips4

Linked PRs

  • gh-115999: Disable the specializing adaptive interpreter in free-threaded builds #116013
  • gh-115999: Implement thread-local bytecode and enable specialization for BINARY_OP #123926
  • gh-115999: Refactor LOAD_GLOBAL specializations to avoid reloading {globals, builtins} keys #124953
  • gh-115999: Stop the world when invalidating function versions #124997
  • gh-115999: Add free-threaded specialization for COMPARE_OP #126410
  • gh-115999: Introduce helpers for (un)specializing instructions #126414
  • gh-115999: Fix gdb support for libpython.so after thread-local bytecode change #126440
  • gh-115999: Add free-threaded specialization for CONTAINS_OP #126450
  • gh-115999: Move specializer test from test_dis to test_opcache #126498
  • gh-115999: Restore SET_OPCODE_OR_RETURN removed in GH-126414 #126515
  • gh-115999: Add free-threaded specialization for UNPACK_SEQUENCE #126600
  • gh-115999: Specialize LOAD_GLOBAL in free-threaded builds #126607
  • gh-115999: Add free-threaded specialization for TO_BOOL #126616
  • gh-115999: Don't take a reason in unspecialize #127030
  • gh-115999: Enable specialization of CALL instructions in free-threaded builds #127123
  • gh-115999: Specialize LOAD_SUPER_ATTR in free-threaded builds #127128
  • gh-115999: Record success in specialize #127167
  • gh-115999: Add free-threaded specialization for STORE_SUBSCR #127169
  • gh-115999: Add partial free-thread specialization for BINARY_SUBSCR #127227
  • gh-115999: Add free-threaded specialization for SEND. #127426
  • gh-115999: Use light-weight lock for UNPACK_SEQUENCE_LIST #127514
  • gh-115999: Specialize loading attributes from modules in free-threaded builds #127711
  • gh-115999: Specialize CALL_KW in free-threaded builds #127713
  • gh-115999: Enable BINARY_SUBSCR_GETITEM for free-threaded build #127737
  • gh-115999: Specialize STORE_ATTR in free-threaded builds. #127838
  • gh-115999: Specialize LOAD_ATTR for instance and class receivers in free-threaded builds #128164
  • gh-115999: Update test_opcache to test with nested method #128166
  • gh-115999: Make list and tuple iteration more thread-safe. #128637
  • gh-115999: Add free-threaded specialization for FOR_ITER #128798
  • gh-115999: Enable free-threaded specialization of LOAD_CONST #129365
  • gh-115999: Note Python 3.14 free-threaded changes in What's New #131285
  • [3.14] gh-115999: Note Python 3.14 free-threaded changes in What's New (gh-131285) #133824
  • gh-115999: Add PyCodeObject.co_tlbc to the debug offsets #134286
  • [3.14] gh-115999: Add PyCodeObject.co_tlbc to the debug offsets (GH-134286) #134348
  • gh-115999: remove redundant check in free-threading from _STORE_ATTR_WITH_HINT #136249
Reacted by Donghee Na, Itamar Oren, Carl Meyer, Juhan Oskar Hennoste, Mikhail Efimov, Kirill Podoprigora and Vasily Ryabov

Activity

Next
  1. swtaarrs
    added
    type-featureA feature request or enhancementA feature request or enhancement
    topic-free-threading
    on Feb 27, 2024
  2. swtaarrs
    self-assigned this
    on Feb 27, 2024
  3. brandtbucher commented on Feb 27, 2024

    @brandtbucher
    brandtbucher
    on Feb 27, 2024
    Member
    More actions

    (subscribing myself)

  4. colesbury
    added a commit that references this issue on Mar 1, 2024

    gh-115999: Disable the specializing adaptive interpreter in free-thre…

    339c8e1
  5. swtaarrs
    removed their assignment
    on Mar 1, 2024
  6. swtaarrs commented on Mar 1, 2024

    @swtaarrs
    swtaarrs
    on Mar 1, 2024
    MemberAuthor
    More actions

    This is now a performance (rather than correctness) issue for free-threaded builds, so I'm going to focus on more time-sensitive issues for a while.

  7. woodruffw
    added a commit that references this issue on Mar 4, 2024

    pythongh-115999: Disable the specializing adaptive interpreter in fre…

    fad3958
  8. adorilson
    added a commit that references this issue on Mar 25, 2024

    pythongh-115999: Disable the specializing adaptive interpreter in fre…

    96d4fbd
  9. diegorusso
    added a commit that references this issue on Apr 17, 2024

    pythongh-115999: Disable the specializing adaptive interpreter in fre…

    d31dae8
  10. corona10 commented on Apr 20, 2024

    @corona10
    corona10
    on Apr 20, 2024
    Member
    More actions

    @swtaarrs Out of curiosity, is there any progress or plan for this issue?

  11. Fidget-Spinner commented on Apr 24, 2024

    @Fidget-Spinner
    Fidget-Spinner
    on Apr 24, 2024
    Member
    More actions

    @corona10 I'm planning to work on this after I get the deferred reference stack in. However, there are no concrete plans as of now. I'm really happy for you or anyone else to propose a design for the specializing interpreter with free-threaded safety!

  12. corona10 commented on Apr 25, 2024

    @corona10
    corona10
    on Apr 25, 2024
    Member
    More actions

    @Fidget-Spinner cc @swtaarrs
    Nice. I was also thinking about how to make it thread-safe in a seamless way since I agree with @swtaarrs.
    But there is no good idea yet to solve the issue right now since I am not in a full-time position for this task :)
    So it will be happy to see you have a good plan.
    (I am curious that we can make them per-thread mechanism...)

    By the way, in the short term, can we enable the specializer to be used only for the main thread if we can not solve the issue before 3.13 is released?
    We can easily track the performance degradation between the default build because most of pyperformance benchmark are based on a single thread :)

  13. Fidget-Spinner commented on Apr 26, 2024

    @Fidget-Spinner
    Fidget-Spinner
    on Apr 26, 2024
    Member
    More actions

    @corona10 for 3.13, I think generally we're focusing on scalability across multicore rather than single-threaded perf for 3.13. It's a bit too near to feature freeze for me to feel safe re-enabling specialization at this point. There are a lot of unsolved problems still even with specialization only on the main thread. Consider the following:

    Two threads sharing the same code object, A and B. A is main thread.
    Thread B is in LOAD_ATTR_METHOD_WITH_VALUES's action (after guards, it is in the middle of loading from a method)
    Thread A is in LOAD_ATTR_METHOD_WITH_VALUES's guard, but then deopts, meaning the method reference is now most likely dead/invalid.
    Thread B loads from LOAD_ATTR_METHOD_WITH_VALUE's method, it is now holding a dangling pointer.
    Thread B pushes dangling pointer to the stack. Everything crashes.
    

    I'm reading a few papers to get some inspiration and also looking at how CRuby and other runtimes deal with this. Will post back when I have an actual plan.

    Reacted by Donghee Na, Brett Simmers, Itamar Oren and Erlend E. Aasland
  14. mpage
    self-assigned this
    on Aug 8, 2024
  15. 151 remaining items

    Load more actions
  16. lkollar
    added a commit that references this issue on May 26, 2025

    pythongh-115999: Add PyCodeObject.co_tlbc to the debug offsets (pytho…

    1f6c663
  17. kumaraditya303
    added a commit that references this issue on Jul 4, 2025

    gh-115999: remove redundant check in free-threading from `_STORE_ATTR…

    85f092f
  18. AndPuQing
    added a commit that references this issue on Jul 11, 2025

    pythongh-115999: remove redundant check in free-threading from `_STOR…

    55a5b18
  19. Pranjal095
    added 3 commits that reference this issue on Jul 12, 2025

    pythongh-115999: Note Python 3.14 free-threaded changes in What's New (

    00256f0

    pythongh-115999: Add PyCodeObject.co_tlbc to the debug offsets (pytho…

    06c364b

    pythongh-115999: remove redundant check in free-threading from `_STOR…

    22fcb1b
  20. picnixz
    added a commit that references this issue on Jul 13, 2025

    pythongh-115999: remove redundant check in free-threading from `_STOR…

    809e892
  21. taegyunkim
    added 3 commits that reference this issue on Aug 4, 2025

    pythongh-115999: Note Python 3.14 free-threaded changes in What's New (

    3383174

    pythongh-115999: Add PyCodeObject.co_tlbc to the debug offsets (pytho…

    afec0f3

    pythongh-115999: remove redundant check in free-threading from `_STOR…

    fbbc3b8
  22. Agent-Hellboy
    added a commit that references this issue on Aug 19, 2025

    pythongh-115999: remove redundant check in free-threading from `_STOR…

    60864e7
  23. eendebakpt
    added 4 commits that reference this issue on May 22, 2026

    gh-NNNNN: Make _STORE_ATTR_SLOT lock-free on the free-threaded build

    73d3dc3

    gh-NNNNN: Make _STORE_ATTR_SLOT lock-free on the free-threaded build

    2cf7c01

    gh-NNNNN: Make _STORE_ATTR_SLOT lock-free on the free-threaded build

    17cca5e

    gh-NNNNN: Make _STORE_ATTR_SLOT lock-free on the free-threaded build

    e72e080
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @mpage
    mpage

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-free-threadingtype-featureA feature request or enhancementA feature request or enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    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.