Opened 5 weeks ago

Closed 4 days ago

#35998 closed Cleanup/optimization (fixed)

Add caching to urlize

Reported by: Sarah Boyce Owned by: Sarah Boyce
Component: Template 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 Natalia Bidart)

urlize will check every word for whether it is a url (and then updates the url to be a html link).
We can add some form of caching so that it doesn't repeat the checks on the same "word"

PR: https://github.com/django/django/pull/18665

Benchmarks:

Before:

>>> import cProfile
>>> from django.template.defaultfilters import urlize
>>> cProfile.run("urlize('Django. ' * 1_000)")
         61048 function calls (59047 primitive calls) in 0.030 seconds

After:

>>> import cProfile
>>> from django.template.defaultfilters import urlize
>>> cProfile.run("urlize('Django. ' * 1_000)")
         3783 function calls (3702 primitive calls) in 0.005 seconds

PR to add benchmark to django-asv: https://github.com/django/django-asv/pull/91

Change History (3)

comment:1 by Natalia Bidart, 5 weeks ago

Description: modified (diff)
Owner: set to Sarah Boyce
Status: newassigned
Triage Stage: UnreviewedAccepted
Version: 5.1dev

Thank you Sarah, makes sense to me.

comment:2 by Sarah Boyce, 4 days ago

Triage Stage: AcceptedReady for checkin

comment:3 by Sarah Boyce <42296566+sarahboyce@…>, 4 days ago

Resolution: fixed
Status: assignedclosed

In b721f127:

Fixed #35998 -- Added caching to django.utils.html.urlize().

Note: See TracTickets for help on using tickets.
Back to Top