Yelp / bravado-core

Other
109 stars 98 forks source link

Use lazy attributes on model #330

Closed macisamuele closed 5 years ago

macisamuele commented 5 years ago

The goal of this PR is to use lazy evaluated and cached attributes on the model class. By doing so we can avoid to pre-evaluate, for all the models, certain features like _properties or _inherits_from which could be time consuming.

Thanks to the usage of @lazy_class_attribute we do evaluate the property only once per model type and reuse the evaluation result for the following calls.

An other change done by this PR is to use slots in the Model, thanks to this we can reduce the memory footprint of the model instances without negatively impacting the performances.

NOTE: PR #329 objective was only to extend @cached_property to be used in meta classes, the extension has not be used here because we would have had to override __getattribute__ as well causing a performance hit of ~7-9%.

coveralls commented 5 years ago

Coverage Status

Coverage decreased (-0.2%) to 98.313% when pulling 939c17c2b2beca1744c6ac880916aedebc0627ba on macisamuele:maci-use-lazy-attributes-on-Model into 89774d2af9c3dc81f40f9a73d7bad77207166ea5 on Yelp:master.