Skip to content

Speed up Attribute instantiation. #70

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

Merged
merged 3 commits into from
Aug 24, 2016

Conversation

Tinche
Copy link
Member

@Tinche Tinche commented Aug 22, 2016

Hello, it's me again.

This speeds up Attribute instantiation.

Before:

> pyperf timeit --rigorous -g -s "from attr import Attribute, NOTHING" "Attribute(name='test', default=NOTHING, validator=None, repr=True, cmp=True, hash=True, init=True)"
........................................
5.58 us:  2 #########
5.63 us:  6 ############################
5.68 us:  5 #######################
5.72 us:  9 ##########################################
5.77 us: 11 ###################################################
5.81 us: 17 ###############################################################################
5.86 us:  7 #################################
5.91 us: 10 ##############################################
5.95 us: 15 ######################################################################
6.00 us: 13 ############################################################
6.05 us:  8 #####################################
6.09 us:  6 ############################
6.14 us:  2 #########
6.18 us:  2 #########
6.23 us:  2 #########
6.28 us:  1 #####
6.32 us:  2 #########
6.37 us:  0 |
6.41 us:  0 |
6.46 us:  0 |
6.51 us:  2 #########

Median +- std dev: 5.94 us +- 0.18 us

After:

> pyperf timeit --rigorous -g -s "from attr import Attribute, NOTHING" "Attribute(name='test', default=NOTHING, validator=None, repr=True, cmp=True, hash=True, init=True)"
........................................
2.20 us:  1 #####
2.22 us:  3 ################
2.23 us:  6 ################################
2.24 us:  9 ###############################################
2.26 us: 14 ##########################################################################
2.27 us: 14 ##########################################################################
2.28 us:  8 ##########################################
2.30 us:  8 ##########################################
2.31 us: 15 ###############################################################################
2.33 us:  9 ###############################################
2.34 us:  7 #####################################
2.35 us:  4 #####################
2.37 us:  3 ################
2.38 us:  5 ##########################
2.39 us:  6 ################################
2.41 us:  6 ################################
2.42 us:  1 #####
2.43 us:  0 |
2.45 us:  0 |
2.46 us:  0 |
2.48 us:  1 #####

Median +- std dev: 2.31 us +- 0.06 us

The gains are significant, and likely to help a lot of users. 🏎

@Tinche
Copy link
Member Author

Tinche commented Aug 22, 2016

Ugh, Python 2 has slightly different error messages. I'll get around to it.

@hynek
Copy link
Member

hynek commented Aug 22, 2016

16.1’s code name is gonna be “Turbo” ;)

@Tinche
Copy link
Member Author

Tinche commented Aug 22, 2016

Is it ok if I just remove the test_missing_argument test? Attribute is basically a normal class now, with minimal logic in the initializer. I could put in the Py2 error message but I feel like we're testing whether classes need to take all their __init__ args at this point.

Limit attribute count in nested Hypothesis classes to 50, like for simple classes.
@codecov-io
Copy link

codecov-io commented Aug 22, 2016

Current coverage is 100% (diff: 100%)

Merging #70 into master will not change coverage

@@           master   #70   diff @@
===================================
  Files           8     8          
  Lines         393   395     +2   
  Methods         0     0          
  Messages        0     0          
  Branches       90    87     -3   
===================================
+ Hits          393   395     +2   
  Misses          0     0          
  Partials        0     0          

Powered by Codecov. Last update dd4140e...fec9eec

@hynek
Copy link
Member

hynek commented Aug 23, 2016

yeah ok

@Tinche
Copy link
Member Author

Tinche commented Aug 23, 2016

Le ping.

@hynek hynek merged commit a7ba512 into python-attrs:master Aug 24, 2016
@Tinche Tinche deleted the optimization/faster-attribute branch August 24, 2016 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants