Repository navigation
Improve astuple performance for atomic dictionary keys and values - #1646
Johnny-Kao wants to merge 6 commits into
Conversation
|
Just wanted to follow up on this PR since it's been open for about a month. Happy to work on this more. Thanks! |
Merging this PR will improve performance by ×3.22 warnings
Performance Changes
Tip Curious why performance improved? Comment Comparing Footnotes
|
hynek
left a comment
There was a problem hiding this comment.
I have added a baseline benchmark to main and it seems to help but the tests and test docstrings violate basically all our rules. Please check out the contributing guide, I don't have time to do the fixups myself right now.
|
Thanks, Hynek. I've updated the tests and docstrings to follow the contributing guide, and fixed the changelog filename. CI is green now. |
Summary
Hi again!
Following up on the merged #1636, I noticed that
astuple()still performs unnecessaryhas()checks when processing dictionary keys and values.I made the same small change for dictionary keys and values, so
astuple()can skip unnecessary checks.For dictionaries with 1,000 atomic entries, this makes it 2.62× faster, with no change in behavior.
Details (for reference only)
CPython 3.14, Linux, 1,000 dictionary entries:
Validation:
Pull Request Checklist
mainbranch..pyi).typing_tests/baseline.pyor, if necessary,typing_tests/mypy.py.attr/__init__.pyi, they've also been re-imported inattrs/__init__.pyi.docs/api.rstby hand.@attr.s()and@attrs.define()have to be added by hand too.versionadded,versionchanged, ordeprecateddirectives..rstand.mdfiles is written using semantic newlines.changelog.d.