jaysonsantos / jinja-assets-compressor

A Jinja extension (compatible with Flask and other frameworks) to compile and/or compress your assets.
Other
93 stars 10 forks source link

Speed up offline compress step with in-memory cache #65

Closed alanhamlett closed 6 years ago

alanhamlett commented 6 years ago

Running offline compression is slow (python -m jac.contrib.flask my_flask_module:create_app). This change uses an in-memory hash to prevent re-compressing the same file more than once. If templates share common script files, this can speed up the offline compression step:

Before

time python -m jac.contrib.flask test:app
Deleting previously compressed files in /Users/alan/projects/test/test/static/sdist
Compressing static assets into /Users/alan/projects/test/test/static/sdist
Finished offline-compressing static assets.
real    4m23.766s
user    5m4.898s
sys 0m30.058s

After

time python -m jac.contrib.flask test:app
Deleting previously compressed files in /Users/alan/projects/test/test/static/sdist
Compressing static assets into /Users/alan/projects/test/test/static/sdist
Finished offline-compressing static assets.
real    1m37.951s
user    1m38.567s
sys 0m13.137s

Time saved: 2m46s

Also caches make_hash to prevent re-hashing the contents of static assets on every http request when offline compress is enabled.


This change is Reviewable

jaysonsantos commented 6 years ago

Hey @alanhamlett thank you for the PR, I will release a new version soon.