Changes between Initial Version and Version 1 of Ticket #33007, comment 2
- Timestamp:
- Aug 10, 2021, 10:31:21 AM (3 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #33007, comment 2
initial v1 1 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]?1 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 `self._bound_fields_cache` instead of going through the extra layer of indirection of `BaseForm.__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]?