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
2.8.0 performance regression compared to 2.7.3 #485
Comments
Got the same issue, are we planning to do something with that? |
ping @mitsuhiko |
i can see a lot of extra IO after adding line
|
Encountered the same problem. The FileSystemLoader is reading disk even if the template is in cache due to some logic error in Environment._load_template() introduced in 6671b9. It is deadly in a purely async web server. Downgrade to 2.7.3 for now. |
I think this need to be fixed in 2.8.1... |
In 6671b97 the load_template method was altered to use a cache key other than the template name. The key chosen was the abs path as returned from the loader get_source method. Unless there is no path in which case the name is used. Unfortunately this introduced a performance regression, pallets#485, as the get_source method (in the FileStoreLoader) loads the template (causing IO). The purpose of pallets#332 was to allow the loader to change whilst ensuring the correct template was loaded, i.e. to fix this case env.loader = loader1 env.get_template('index.html') # return loader1/index.html env.loader = loader2 env.get_template('index.html') # also return loader1/index.html because of cache This commit changes the cache key to be a combination of a hash of the loader and the template name. Therefore fixing the above case without calling the get_source method and thereby avoiding the IO load.
In 6671b97 the load_template method was altered to use a cache key other than the template name. The key chosen was the abs path as returned from the loader get_source method. Unless there is no path in which case the name is used. Unfortunately this introduced a performance regression, pallets#485, as the get_source method (in the FileStoreLoader) loads the template (causing IO). The purpose of pallets#332 was to allow the loader to change whilst ensuring the correct template was loaded, i.e. to fix this case env.loader = loader1 env.get_template('index.html') # return loader1/index.html env.loader = loader2 env.get_template('index.html') # also return loader1/index.html because of cache This commit changes the cache key to be a combination of a hash of the loader and the template name. Therefore fixing the above case without calling the get_source method and thereby avoiding the IO load. A test has been added to ensure the above case works as expected, this required a minor refactor of the caching tests.
In 6671b97 the load_template method was altered to use a cache key other than the template name. The key chosen was the abs path as returned from the loader get_source method. Unless there is no path in which case the name is used. Unfortunately this introduced a performance regression, pallets#485, as the get_source method (in the FileStoreLoader) loads the template (causing IO). The purpose of pallets#332 was to allow the loader to change whilst ensuring the correct template was loaded, i.e. to fix this case env.loader = loader1 env.get_template('index.html') # return loader1/index.html env.loader = loader2 env.get_template('index.html') # also return loader1/index.html because of cache This commit changes the cache key to be a tuple of the loader and the template name. Therefore fixing the above case without calling the get_source method and thereby avoiding the IO load. A test has been added to ensure the above case works as expected, this required a minor refactor of the caching tests.
In 6671b97 the load_template method was altered to use a cache key other than the template name. The key chosen was the abs path as returned from the loader get_source method. Unless there is no path in which case the name is used. Unfortunately this introduced a performance regression, pallets#485, as the get_source method (in the FileStoreLoader) loads the template (causing IO). The purpose of pallets#332 was to allow the loader to change whilst ensuring the correct template was loaded, i.e. to fix this case env.loader = loader1 env.get_template('index.html') # return loader1/index.html env.loader = loader2 env.get_template('index.html') # also return loader1/index.html because of cache This commit changes the cache key to be a tuple of the loader and the template name. Therefore fixing the above case without calling the get_source method and thereby avoiding the IO load. A test has been added to ensure the above case works as expected, this required a minor refactor of the caching tests.
In 6671b97 the load_template method was altered to use a cache key other than the template name. The key chosen was the abs path as returned from the loader get_source method. Unless there is no path in which case the name is used. Unfortunately this introduced a performance regression, pallets#485, as the get_source method (in the FileStoreLoader) loads the template (causing IO). The purpose of pallets#332 was to allow the loader to change whilst ensuring the correct template was loaded, i.e. to fix this case env.loader = loader1 env.get_template('index.html') # return loader1/index.html env.loader = loader2 env.get_template('index.html') # also return loader1/index.html because of cache This commit changes the cache key to be a tuple of the id(loader) and the template name. Therefore fixing the above case without calling the get_source method and thereby avoiding the IO load. A test has been added to ensure the above case works as expected, this required a minor refactor of the caching tests.
It seems like with Jinja2 2.8.0 there's extra IO being performed even with templates being cached and auto reloading disabled.
Test case (we use template includes a lot and this is a relatively good test):
With Jinja2 2.7.3:
With Jinja2 2.8.0:
This is CPython 2.7.10.
This regression is likely to have been introduced by:
The text was updated successfully, but these errors were encountered: