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-112075: refactor dictionary lookup functions for better re-usability by DinoV · Pull Request #114629 · python/cpython

Conversation

@DinoV

@DinoV DinoV commented Jan 27, 2024 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Refactor dictionary lookup functions for better usability

Free threaded builds of Python will need to expand upon the lookup functions to have thread-safe versions of them that can be run without the dictionary being locked. These lookups will just be subtly different - they'll use atomic loads and they'll need to contain some extra checks for values that may change in flight.

Currently there are 3 loookup functions so for free-threaded builds we'll need to get 6 of them. That's going to be a good amount of copy and pasting with sometimes subtle differences. So I'm curious if people would prefer an approach like this as opposed to the copy and pasting. I don't want to use macros as that'd destroy debugging. If we're concerned about perf implications for non-mainstream compilers or don't like this approach I can just go ahead with copy and pasting.

This factors these functions into one core function which contains the loop, and 3 comparison helper functions which implement the different comparisons. In free-threaded versions we'll get modified versions of these comparisons as that's where the differences will be.

This still generates nearly identical code in LTO builds, here's the before https://pastebin.com/UZdhKc6f and the after: https://pastebin.com/sdhcFZP5. Even in non-LTO builds the code is remarkably similar (with the new code maybe resembling the LTO code a little bit more as for some reason the non-LTO code gets a weird jmp at the beginning).

There is technically one change here in that the loop unrolling has been applied to all versions of the code, although we could easily have 2 versions of the loop function with one unrolled and one not-unrolled.

Perf seems to be be mostly neutral to me: https://pastebin.com/LPJYZAj4

  • Issue: Make dict objects thread-safe in --disable-gil builds #112075

Sorry, something went wrong.

Uh oh!

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

All reactions
@DinoV DinoV added skip news topic-free-threading labels Jan 27, 2024
@DinoV
DinoV requested a review from colesbury January 27, 2024 00:07
@bedevere-app bedevere-app Bot mentioned this pull request Jan 27, 2024
Make dict objects thread-safe in --disable-gil builds #112075
Closed
@DinoV
DinoV marked this pull request as ready for review January 27, 2024 01:11
@DinoV
DinoV requested review from markshannon and methane as code owners January 27, 2024 01:11
@bedevere-app bedevere-app Bot added the awaiting core review label Jan 27, 2024
methane
methane approved these changes Jan 27, 2024
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Jan 27, 2024
colesbury
colesbury reviewed Jan 29, 2024
View reviewed changes

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

A few comments below, but overall looks good to me.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Objects/dictobject.c Resolved

Uh oh!

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

Comment thread Objects/dictobject.c Resolved

Uh oh!

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

Comment thread Objects/dictobject.c Resolved

Uh oh!

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

Comment thread Objects/dictobject.c Resolved

Uh oh!

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

DinoV added 2 commits January 29, 2024 15:50
@DinoV
Refactor dict lookup functions to use force inline helpers
64a76c9
@DinoV
Use 1/0 for successful comparison eq/ne
bd4fba9
@DinoV
DinoV force-pushed the nogil_dict_refactor_lookup branch from 32a6a41 to bd4fba9 Compare January 29, 2024 23:50
@DinoV
DinoV merged commit 0990d55 into python:main Jan 30, 2024
@bedevere-app bedevere-app Bot removed the awaiting merge label Jan 30, 2024
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
@DinoV @aisk
pythongh-112075: refactor dictionary lookup functions for better re-u…
8a0a33b
…sability (python#114629)

Refactor dict lookup functions to use force inline helpers
@DinoV
DinoV deleted the nogil_dict_refactor_lookup branch May 31, 2024 18:23
@vstinner vstinner mentioned this pull request Jul 8, 2024
gh-121266: Remove Py_ALWAYS_INLINE in dictobject.c #121493
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@colesbury colesbury colesbury left review comments
@methane methane methane 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 topic-free-threading

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

@DinoV @methane @colesbury
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.