Opened 5 years ago

Last modified 5 years ago

#30772 closed Cleanup/optimization

Template Cache "make_template_fragment_key" function speed up & switch to SHA256 — at Version 2

Reported by: Daniel Owned by: nobody
Component: Core (Cache system) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Daniel)

The make_template_fragment_key function in django.core.cache.utils has the following (minor) issues:

  • Creates a string of all joined vary_on args to send to the hashing function, rather than using the hashlib .update() method.

Here is a version solving these, switching to SHA256, and speeding up the function quite a bit:

https://github.com/danthedeckie/django/tree/simplified_make_template_fragment_key

And PR: https://github.com/django/django/pull/11772

And here's the repo showing performance improvement:

https://github.com/danthedeckie/make_template_fragment_key_test

Which seems to be faster in every case.

The downside of this is that the cache key is now different from before. The tests have been updated to the new values.

There are other cache key generating functions used in other places which use MD5 still - if switching to SHA256 it would make sense to me to change those at the same time, meaning only one time invalidating keys on upgrade.

Thoughts?

Change History (2)

comment:1 by Daniel, 5 years ago

Description: modified (diff)

comment:2 by Daniel, 5 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top