-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
benchmark for cattrs #513
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
benchmark for cattrs #513
Conversation
Codecov Report
@@ Coverage Diff @@
## master #513 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 19 19
Lines 3237 3237
Branches 642 642
=====================================
Hits 3237 3237Continue to review full report at Codecov.
|
|
Thanks, I'm keen to include Hand written checks are always going to be much faster, but they're not the same thing:
IMHO this isn't a mistake in your PR, but rather that attr generally has a different use case from the other libraries tested here:
Perhaps best to add another benchmark for simple type checks were only attr and pydantic are benchmarked and leave attr out of the "web API style" benchmark. What do you think? Also I have a dataset I've always used for generating benchmarks. It was generated with the same random case generator and it's not perfect, but I've always used it in the past so for consistency I think best to carry on using it. Just put cases.json into |
I agree, I just came across via I originally tried to use
I surely agree. Would you then add another section in the docs? Shall I?
|
If you're keen that would be great. Yes, another sub-session just below the current benchmarks. |
* add env "ATTRS=1" to benchmark runner to only compare again the two and save results in separate csv * added section to docs/index
|
So: I added a benchmark for using Benchmarks are run using the |
|
I'm not sure I see the point in having tests with bot attr and cattr, I think we should use just one. Also, maybe I was wasn't that clear before, but what I was suggesting for the second benchmark set was to only validate the standard type stuff attr is designed (as far as I understand it) to check, and avoid all the more complex checks shown in the first set of benchmarks. Eg. have a second simpler pydantic model for this benchmark and remove all the custom validation logic from the attr case. |
|
Well, after all I do not care much. I find it this way, i.e. have the same benchmark but with differently flavoured tools, more informative. I tells me that when my required validations and/or non standard types are limited - or if I am willing to write custom validations logic - that I can gain considerable speed-ups. Actually we use So - what now? If you find a "restricted" benchmark more informative I can see if I find the time to strip down the case here (to |
Sorry to take up more of your time, but yes I think the second benchmarks should be restricted - the kind of thing you might check in a package to make sure people are using it (roughly) correctly, rather than what you would check in a public API. If this isn't clear, let me know and I'll give an exact example. If this sounds like too much work, let me know and I'll try to do it when I get time. Thanks again. |
|
In my own implementation of the benchmark using attrs+cattrs (#543 referenced above), I was getting ~3x faster execution for attrs+cattrs relative to pydantic. Trying to get to the bottom of why the attrs+cattrs benchmark was faster (and if anything could be easily modified to catch up), I did some line-by-line profiling, and while nothing stood out to me as an obvious bottleneck, I did notice that you pay a price for some of the validations even when they are disabled (e.g., when validating a string, @samuelcolvin Is there a way to actually modify the set of validators that gets called for a given model? That seems more reflective of my understanding of how attrs+cattrs performs validation, and I would expect it to help speed things up if, for instance, you only want type validation. It looked to me like something was happening where there was iteration over each field's list of validators, but if I touched that list (even just removing items from it) it surprisingly caused everything to run much more slowly. @sebastianmika for what it's worth, if you are trying to resolve a bottleneck, I was able to get a ~30% speed improvement in the pydantic benchmark by cythonizing just |
|
discussion on performance improvements moved to #547. |
|
@sebastianmika thanks for this I'm going to make some changes to get it the way I want it (partially back to how it started 😄). Will work on it when I get a chance. |
|
@samuelcolvin Cool - and sorry for my lameness. I took the freedom to make yet another proposal now that |
|
Thanks so much, I'll look into it when I get a chance and will response/make some more changes. |
|
Thanks so much for this, sorry I haven't dealt with it. I'm going to defer further changes to benchmarks until after v1 (see #576), but after that I promise to deal with this. Sorry again for the delay. |
|
Sorry for the extremely long delay on this. I've updated your PR to:
I'll merge this once it's passed. |
* benchmark for attr * update HISTORY.rst * * added benchmark using cattr * add env "ATTRS=1" to benchmark runner to only compare again the two and save results in separate csv * added section to docs/index * nits * re-run benchmark with cython pydantic; merge results back to main benchmarks results table * pin pydantic to top of benchmark report * remove attrs, fix cattrs * update benchmarks output * add change
Change Summary
Added a benchmark for
attr(http://www.attrs.org/en/stable/index.html). Run them on my machine (Mac) in a fresh venv with python 3.7.3Checklist
HISTORY.rsthas been updated#<number>@<whomever>