Skip to content

gh-143732: allow dict subclasses to be specialized - #148128

Merged
markshannon merged 23 commits into
python:mainfrom
kumaraditya303:jit-dict-opt
May 4, 2026
Merged

gh-143732: allow dict subclasses to be specialized #148128
markshannon merged 23 commits into
python:mainfrom
kumaraditya303:jit-dict-opt

Conversation

@kumaraditya303

@kumaraditya303kumaraditya303 commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

This is revival of #132383 which allowed specialization for dict subclasses which do not override __getitem__. This PR also allows specialization for dict subclasses which do not override __setitem__.

This is primarily targeted for defaultdict which is the most performance critical subclass of dict.

@kumaraditya303
kumaraditya303 marked this pull request as ready for review April 5, 2026 18:39
@kumaraditya303kumaraditya303 added the performance Performance or resource usage label Apr 5, 2026
@kumaraditya303

Copy link
Copy Markdown
ContributorAuthor

@markshannon Can you take a look at this? I'd like get this in time for the beta release.

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

Looks good overall.
The old uops need to be removed and some assertions may no longer be valid.

Also, take care with recorded types. Only strengthen type information on proven or guards, not recorded information.

Comment threadPython/bytecodes.c
Comment threadPython/bytecodes.c
Comment threadPython/bytecodes.c Outdated
Comment threadPython/optimizer_bytecodes.c
Comment threadPython/optimizer_bytecodes.c
Comment threadPython/bytecodes.c Outdated
Comment threadPython/bytecodes.c Outdated
Comment threadPython/bytecodes.c Outdated
@markshannon

Copy link
Copy Markdown
Member

GitHub doen't put comments in order, it seems. The "above" in the comments refers to earlier lines, not earlier comments.

@kumaraditya303

Copy link
Copy Markdown
ContributorAuthor

I still think the assert(PyDict_Check(dict)); asserts should be removed.

I removed the assertions now and added watchers for all cases.

I have made the requested changes; please review again

@bedevere-app

Copy link
Copy Markdown

Thanks for making the requested changes!

@markshannon: please review the changes made to this pull request.

@read-the-docs-community

read-the-docs-communityBot commented Apr 30, 2026

Copy link
Copy Markdown

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

I still think we need more watchers. Sorry, I should have spotted that in the last review.

Comment threadPython/optimizer_bytecodes.c
@bedevere-app

Copy link
Copy Markdown

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

And if you don't make the requested changes, you will be poked with soft cushions!

@kumaraditya303

Copy link
Copy Markdown
ContributorAuthor

Looks like the CI is affected by the Ubuntu outage today.

@kumaraditya303

Copy link
Copy Markdown
ContributorAuthor

I have made the requested changes; please review again

@bedevere-app

Copy link
Copy Markdown

Thanks for making the requested changes!

@markshannon: please review the changes made to this pull request.

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

This looks good now. Thanks.

@markshannon
markshannon merged commit 5847931 into python:mainMay 4, 2026
79 of 82 checks passed
@bedevere-bot

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 Debian root 3.x (tier-1) has failed when building commit 5847931.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/345/builds/14120) and take a look at the build logs.
  4. Check if the failure is related to this commit (5847931) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/345/builds/14120

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
File "/root/buildarea/3.x.angelico-debian-amd64/build/Lib/test/support/__init__.py", line 948, in gc_collect
gc.collect()
~~~~~~~~~~^^ResourceWarning: unclosed file <_io.FileIO name=11 mode='wb' closefd=True>

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

Labels

performancePerformance or resource usageskip news

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@kumaraditya303@markshannon@bedevere-bot