#35998: Add caching to urlize
-------------------------------------+-------------------------------------
Reporter: Sarah Boyce | Owner: Sarah
Type: | Boyce
Cleanup/optimization | Status: assigned
Component: Template system | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):
* owner: (none) => Sarah Boyce
* stage: Unreviewed => Accepted
* status: new => assigned
* version: 5.1 => dev
Old description:
> `urlize` will checks 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
New description:
`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
--
Comment:
Thank you Sarah, makes sense to me.
--
Ticket URL: <https://code.djangoproject.com/ticket/35998#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/01070193b5f43222-3913ef04-4857-4425-9b53-f4926ee10e8c-000000%40eu-central-1.amazonses.com.