-
-
Notifications
You must be signed in to change notification settings - Fork 382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Performance Improvement for evolve function #1145
Comments
It would look something like this:
|
A note on kwargs performance, this is a general fact about Python, not an attrs-specific performance degradation. Calling any Callable using positional args will be faster than passing the same args as kwargs. As for the evolve registry, another alternative is to just stick another method on the class as an |
Sorry for the late answer, this came up while I was afh (away from home ;)) for a prolonged time and I've been reeling ever since. I think this is interesting since we've just implemented As Tin writes, I don't think it's worth to do code gen because that would slow down class generation further, but maybe we could do some optimizations for the 3.13+ case? Currently, |
Hello,
I have been recently working with the evolve function in attrs and noticed some performance issues which I believe could be improved.
Here is an example I tried:
The evolve function in this case appears to be almost three times slower than creating a new instance of the class manually.
Upon investigation, I discovered that a significant amount of time was spent on creating class Fields, iterating them, and updating unchanged values.
Additionally, I noticed that creating instances using kwargs took approximately 30% more time than using args:
print(timeit.timeit("A(a=2, b=a.b)", globals=globals())) # 0.2635 seconds
Given these findings, I suggest that we could improve the performance of the evolve function by generating per class functions the first time that the class is evolved. These functions would look something like this:
I am open to creating a PR that would implement these changes if you think this is a good idea. I look forward to your thoughts on this.
Thank you.
The text was updated successfully, but these errors were encountered: