-
Notifications
You must be signed in to change notification settings - Fork 1k
perf: update template renderer paths to use package qualifiers #18277
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
base: main
Are you sure you want to change the base?
perf: update template renderer paths to use package qualifiers #18277
Conversation
Avoid unnecessary template lookup failures by specifying full package paths for all template renderers. Previously, for endpoints like /simple/<package>, the template resolver would first attempt to find 'warehouse.api:api/simple/detail.html' which would always fail, then fall back to 'templates/api/simple/detail.html'. By using explicit package qualifiers like 'warehouse:templates/api/simple/detail.html', we skip the initial failed lookup and exception handling. This provides a small performance optimization by eliminating known failed disk lookups, as well as avoiding exception traceback generation when ddtrace is enabled.
What should we do about: Lines 728 to 733 in 3a1f8c8
Is this proposed change even desired for the minimal gain vs having the default search path? |
An alternative here is to move all the templates into their respective module paths, e.g. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I generally like this, as it makes it more explicit and clear which template is where.
Sadly, the functional tests (webtest
-style tests) don't cover every @view_config
instance to validate that the changes are safe, and we'd only find out at runtime if the template is truly missing.
Can you conceive of a way to validate that each of these template paths exists in a lint/test phase, or another way to verify that these string changes don't break at runtime?
#18366 likely solves the concern, so once that lands, this PR should be checked against that for accuracy. |
@brettlangdon looks like the checker I wrote doesn't yet account for the updated paths - would you want to take a stab at adding that? |
Avoid unnecessary template lookup failures by specifying full package paths for all template renderers. Previously, for endpoints like
/simple/<package>
, the template resolver would first attempt to find'warehouse.api:api/simple/detail.html'
which would always fail, then fall back to'templates/api/simple/detail.html'
. By using explicit package qualifiers like'warehouse:templates/api/simple/detail.html'
, we skip the initial failed lookup and exception handling.This provides a small performance optimization by eliminating known failed disk lookups, as well as avoiding exception traceback generation when ddtrace is enabled (for attaching the traceback to the span metadata).
Testing locally, the template load time goes from ~830us to ~80us, and template rendering time goes from ~4ms to ~3.7ms... a small optimization, but an easy win.