#30949: Use functools.cached_property instead of
django.utils.functional.cached_property.
-------------------------------------+-------------------------------------
Reporter: Thomas Grainger | Owner: David
Type: | Smith
Cleanup/optimization | Status: assigned
Component: Utilities | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Someday/Maybe
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by David Smith):
We're nearing the point where Python 3.8 will become the minimum supported
version. I've therefore started to look at this ticket as I think
"someday" has now arrived, and hopefully we can make a decision one way or
the other with this.
The first thing I've done is to look at the performance of the two
functions and have put together a script
[https://gist.github.com/smithdc1/873688e563c66a0dd253602aab6fc3e2 here].
Running it with isolated CPUs is giving repeatable results that show very
little (if anything) between the two functions. This benchmark was run
with Python 3.9.
There were previous comments about the impact of the `RLock` mechanism,
this is only used the first time when the
[https://github.com/python/cpython/blob/63298930fb531ba2bb4f23bc3b915dbf1e17e9e1/Lib/functools.py#L964
value is set]. I suspect this is why I'm seeing little performance
difference between the two. (Hopefully, I've understood the context of
these comments correctly)
If no one has any objections at this stage, I'll prepare a patch in due
course.
{{{
python bench_cached_property.py
.....................
Django Cache: Mean +- std dev: 1.07 us +- 0.05 us
.....................
Python Cache: Mean +- std dev: 1.08 us +- 0.05 us
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30949#comment:6>
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 on the web visit
https://groups.google.com/d/msgid/django-updates/067.5ab43d5ba0696a5e667b1b33276fd63c%40djangoproject.com.