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-115999: Add free-threaded specialization for `STORE_SUBSCR` by colesbury · Pull Request #127169 · python/cpython

Conversation

@colesbury

@colesbury colesbury commented Nov 22, 2024 •
edited by bedevere-app Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

The specialization only depends on the type, so no special thread-safety considerations there.

STORE_SUBSCR_LIST_INT needs to lock the list before modifying it.

_PyDict_SetItem_Take2 already internally locks the dictionary using a critical section.

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

Sorry, something went wrong.

Uh oh!

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

All reactions
@colesbury
pythongh-115999: Add free-threaded specialization for STORE_SUBSCR
2b63929
The specialization only depends on the type, so no special thread-safety
considerations there.

STORE_SUBSCR_LIST_INT needs to lock the list before modifying it.

`_PyDict_SetItem_Take2` already internally locks the dictionary using a
critical section.
@colesbury colesbury added the skip news label Nov 22, 2024
@colesbury
colesbury requested a review from mpage November 22, 2024 19:07
@colesbury
colesbury requested a review from markshannon as a code owner November 22, 2024 19:07
@bedevere-app bedevere-app Bot added the awaiting core review label Nov 22, 2024
@bedevere-app bedevere-app Bot mentioned this pull request Nov 22, 2024
Make the specializing interpreter thread-safe in --disable-gil builds #115999
Closed
colesbury
colesbury commented Nov 22, 2024
View reviewed changes
Comment thread Python/ceval_macros.h Outdated
// avoid any potentially escaping calls (like PyStackRef_CLOSE) while the
// object is locked.
#ifdef Py_GIL_DISABLED
# define LOCK_OBJECT(op) PyMutex_LockFast(&(_PyObject_CAST(op))->ob_mutex)

@colesbury colesbury Nov 22, 2024

Copy link
Copy Markdown
Contributor 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.

@mpage, I think this locking pattern will be slightly faster than using critical sections inline in bytecodes.c. The downside is that we will deopt if there's any lock contention, but I think that's an okay tradeoff.

If we decide to go with this pattern, we can update UNPACK_SEQUENCE_LIST to use it.

Sorry, something went wrong.

Uh oh!

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

mpage, corona10, and Eclips4 reacted with thumbs up emoji
All reactions
  • 👍 3 reactions

@mpage mpage Nov 22, 2024

Copy link
Copy Markdown
Contributor

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.

That makes sense to me.

Sorry, something went wrong.

Uh oh!

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

All reactions
@colesbury
colesbury requested a review from corona10 November 22, 2024 19:18
@colesbury

colesbury commented Nov 22, 2024

Copy link
Copy Markdown
Contributor Author

@corona10 - I put my name down next to STORE_ATTR, but then got confused and worked on STORE_SUBSCR instead. Sorry!

All reactions

Sorry, something went wrong.

Uh oh!

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

@colesbury

colesbury commented Nov 22, 2024

Copy link
Copy Markdown
Contributor Author

(STORE_ATTR is up for grabs)

corona10 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.

mpage
mpage reviewed Nov 22, 2024
View reviewed changes

@mpage mpage left a comment

Copy link
Copy Markdown
Contributor

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.

Nice! I left one comment/question inline and there's a compiler warning that we need to fix up.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Python/ceval_macros.h Outdated
// avoid any potentially escaping calls (like PyStackRef_CLOSE) while the
// object is locked.
#ifdef Py_GIL_DISABLED
# define LOCK_OBJECT(op) PyMutex_LockFast(&(_PyObject_CAST(op))->ob_mutex)

@mpage mpage Nov 22, 2024

Copy link
Copy Markdown
Contributor

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.

That makes sense to me.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Python/specialize.c Resolved

Uh oh!

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

@corona10

corona10 commented Nov 22, 2024

Copy link
Copy Markdown
Member

I put my name down next to STORE_ATTR, but then got confused and worked on STORE_SUBSCR instead. Sorry!

Race condition with the wrong lock :) Fine, thank you for the work, I've updated the list of issues.

All reactions

Sorry, something went wrong.

Uh oh!

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

corona10
corona10 reviewed Nov 22, 2024
View reviewed changes

@corona10 corona10 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.

Please add test codes at test_opcache.py

cpython/Lib/test/test_opcache.py

Line 1227 in d24a22e

class TestSpecializer(TestBase):

Sorry, something went wrong.

Uh oh!

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

All reactions
corona10
corona10 reviewed Nov 24, 2024
View reviewed changes
Comment thread Python/ceval_macros.h Resolved

Uh oh!

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

@corona10 corona10 mentioned this pull request Nov 24, 2024
gh-115999: Add partial free-thread specialization for BINARY_SUBSCR #127227
Merged
@colesbury @corona10
Update Python/ceval_macros.h
8230581
Co-authored-by: Donghee Na <[email protected]>
corona10
corona10 approved these changes Nov 25, 2024
View reviewed changes

@corona10 corona10 left a comment •
edited
Loading

Uh oh!

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

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.

lgtm (except test code :))

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 Nov 25, 2024
@colesbury

colesbury commented Nov 25, 2024

Copy link
Copy Markdown
Contributor Author

Performance difference is marginal: 1.00x faster (but 99.99% likely to be faster)

https://github.com/facebookexperimental/free-threading-benchmarking/blob/main/results/bm-20241122-3.14.0a2%2B-2b63929-NOGIL/bm-20241122-vultr-x86_64-colesbury-gh_115999_store_subs-3.14.0a2%2B-2b63929-vs-base.md

I think it's worth doing even if the perf is neutral just to minimize divergence with the default (GIL) build.

mpage 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.

@colesbury
colesbury requested a review from mpage November 25, 2024 18:55
@mpage mpage mentioned this pull request Nov 25, 2024
Type slots are not thread-safe in free-threaded builds #127266
Closed
mpage
mpage approved these changes Nov 25, 2024
View reviewed changes
@colesbury
colesbury merged commit 71ede11 into python:main Nov 26, 2024
@bedevere-app bedevere-app Bot removed the awaiting merge label Nov 26, 2024
@colesbury
colesbury deleted the gh-115999-store-subscr branch November 26, 2024 21:46
@corona10 corona10 mentioned this pull request Dec 2, 2024
gh-115999: Use light-weight lock for UNPACK_SEQUENCE_LIST #127514
Merged
@colesbury colesbury mentioned this pull request Dec 2, 2024
gh-127518: Fix pystats build after #127169 #127526
Merged
mdboom added a commit that referenced this pull request Dec 2, 2024
@mdboom
gh-127518: Fix pystats build after #127169 (#127526)
edefb86
gh-127518: Fix pystats build after #127619
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this pull request Jan 8, 2025
@mdboom @srinivasreddy
pythongh-127518: Fix pystats build after python#127169 (python#127526)
1841c79
pythongh-127518: Fix pystats build after python#127619
ebonnal pushed a commit to ebonnal/cpython that referenced this pull request Jan 12, 2025
@colesbury @ebonnal
pythongh-115999: Add free-threaded specialization for STORE_SUBSCR (p…
2a4d4d5
…ython#127169)

The specialization only depends on the type, so no special thread-safety
considerations there.

STORE_SUBSCR_LIST_INT needs to lock the list before modifying it.

`_PyDict_SetItem_Take2` already internally locks the dictionary using a
critical section.
ebonnal pushed a commit to ebonnal/cpython that referenced this pull request Jan 12, 2025
@mdboom @ebonnal
pythongh-127518: Fix pystats build after python#127169 (python#127526)
cf5438d
pythongh-127518: Fix pystats build after python#127619
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@mpage mpage mpage approved these changes
@corona10 corona10 corona10 approved these changes
@markshannon markshannon Awaiting requested review from markshannon markshannon 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.

3 participants

@colesbury @corona10 @mpage
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 01402520 — 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.