-
-
Notifications
You must be signed in to change notification settings - Fork 390
Optimize init validators. #64
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
Optimize init validators. #64
Conversation
Current coverage is 100% (diff: 100%)@@ master #64 diff @@
===================================
Files 8 8
Lines 384 393 +9
Methods 0 0
Messages 0 0
Branches 89 90 +1
===================================
+ Hits 384 393 +9
Misses 0 0
Partials 0 0
|
If we're up for this, converters can be given the same treatment. |
I’m not gonna lie, this looks scary. 😱 But 50% faster is kind of sweet. 🙈 How would a non-public |
I can check later today. I really like the fact that at class definition time we actually know which attributes have validators, and we can generate an (I'll fix the coverage too.) |
Yeah you’re right. I’m just being lazy about rebasing immutable (IOW: don’t check; but do fix :)). |
Dammit, only now I see apparently limiting the number of generated attributes breaks tests!?! Will take a closer look when I have some time. |
It’s hypothesis being too slow again. :| |
this needs a rebase :-P |
also maybe the the average for the number of attributes to a low single digit please. :) that should help with the slownesses… |
Tweak Hypothesis class generation.
3f4826b
to
c9da161
Compare
Pingety ping. |
We’re all going to hell but 16.1 is gonna be majestic. |
OK, here's an idea for an optimization, since we're into that stuff now :)
Assume the attrs class
attr.make_class('C', {'x': attr.ib(validator=validators.instance_of(int)), 'y': attr.ib(), 'z': attr.ib()})
.The master will generate an init like this:
so I was thinking how to improve this. Ideas in sequence:
validate()
callsfields()
. Can we avoid the function call by using the__attrs_attrs__
directly?validate()
is a public facing API, so alas, no.validate()
, and so avoid that call too? Just put the internal validation code in the generated__init__
.__init__
validation code. We don't have to skip attributes without validators every time, we can just not generate the code in the first place.globals
directly, avoid some dict lookups.So now, the generated
__init__
code looks like this:Before:
After:
Even the case of no validators is faster since I omit the call to validate altogether. (~1%)
Complexity for performance. Worth it?