Speedup _setattr usage and fix slight performance regressions#991
Merged
hynek merged 3 commits intopython-attrs:mainfrom Aug 7, 2022
Merged
Conversation
219948a to
c8e0d64
Compare
_setattr usage and fix performance regressions_setattr usage and fix slight performance regressions
Contributor
Author
|
Also worth noting that frozen classes don't scale well when it comes to attribute setting. When comparing setting 3 attributes in frozen and unfrozen slotted classes, you get a difference of about 200 nanoseconds. When you expand the test to 10 attributes, you get a difference of almost 500! (943 vs 445). Looks like the cost of making so many calls is not ideal, but I can't think of a better way of doing this without really stretching the limits of python. |
hynek
approved these changes
Aug 7, 2022
Member
hynek
left a comment
There was a problem hiding this comment.
Thanks, I’m gonna have to take your word for it here. 😅
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fix slight performance regression of #898.
I only noticed this after upgrading to 22.1.0, but the PR i made a while back to speedup the instantiation of frozen classes did so, but at a cost of not scaling correctly the more attributes that need to be set
Didnt want to just revert the commit, so played around a bit and found some optimizations. which are in this pr. They include (partially) going back to some of the old code, but with some optimizations that makes it both scale better and perform better in simple tests, ending up being a win win. Sorry for the slight performance regression this issue caused. It didnt cross to me it wouldnt scale well.
3 arguments performance
attrs-21.4.0attrs-22.1.0this pr10 arguments performace
attrs-21.4.0attrs-22.1.0this prPull Request Check List
Our CI fails if coverage is not 100%.
.pyi).tests/typing_example.py.attr/__init__.pyi, they've also been re-imported inattrs/__init__.pyi.docs/api.rstby hand.@attr.s()have to be added by hand too.versionadded,versionchanged, ordeprecateddirectives.Find the appropriate next version in our
__init__.pyfile..rstfiles is written using semantic newlines.changelog.d.