#33007: `form_clean()` performance
--------------------------------------+------------------------------------
Reporter: David Smith | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Forms | Version: 3.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Comment (by Chris Jerdonek):
That ticket (#32920) was primarily about correctness rather than trying to
do anything about performance. Nevertheless, one possible optimization
that occurred to me while working on it was adding a flag to `BaseForm`
called something like `self._bound_fields_cache_filled`. Then, the
[https://github.com/django/django/blob/b64db05b9cedd96905d637a2d824cbbf428e40e7/django/forms/forms.py#L147-L150
BaseForm._bound_items()] and
[https://github.com/django/django/blob/b64db05b9cedd96905d637a2d824cbbf428e40e7/django/forms/forms.py#L152-L155
BaseForm.__iter__()] iterators could consult that flag at their outset. If
set, the `BoundField` items could be served directly from
`_bound_fields_cache` instead of going through the extra layer of
indirection of `BoundField.__getitem__()`. However, I don't know what's
contributing most in terms of the slow-down. Maybe it's that
`BoundField.initial`
[https://github.com/django/django/blob/b64db05b9cedd96905d637a2d824cbbf428e40e7/django/forms/boundfield.py#L228-L230
uses @cached_property]?
--
Ticket URL: <https://code.djangoproject.com/ticket/33007#comment:2>
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/066.d6b0f10813a65294c0f19b8a8ca00b8e%40djangoproject.com.