nestorsalceda / mamba

The definitive testing tool for Python. Born under the banner of Behavior Driven Development (BDD).
http://nestorsalceda.github.io/mamba
MIT License
518 stars 65 forks source link

Use pickle to cache AST parse; ~25% speedup @ O(100) specs #92

Open PhilHarnish opened 6 years ago

PhilHarnish commented 6 years ago

Consider adding a pkl cache to mamba's transformations.

My nasty, massive repo has the following speedup when using pkl: Before: 853 examples ran (156 pending) in 1.5438 seconds After: 853 examples ran (156 pending) in 1.1454 seconds (~25% faster)

My diff looks like this:

    @pickle_cache.cache_from_file('mamba_spec')
    def _parse_and_transform_ast(self, path):
        with open(path) as f:
        # (...snip...)

Where pickle_cache.cache_from_file() is defined here: https://github.com/PhilHarnish/forge/blob/master/src/data/pickle_cache.py tl;dr: if path is unmodified then the AST is pulled from pkl.

Mamba's requirements are pretty straightforward (eg, function of only "path" and mamba's version number) and so it ought to be easy to accomplish in fewer lines.