#35236: Access Field.attname and Field.column directly
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
Type: | Johnson
Cleanup/optimization | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Adam Johnson):
* has_patch: 0 => 1
* owner: nobody => Adam Johnson
Old description:
> Many field references call `Field.get_attname_column()` or
> `Field.get_attname()`, despite the `attname` and `column` attributes
> containing the computed results (after `contribute_to_class()`). Updating
> those call sites to plain attribute access eliminates some function
> calls, a worthy small speedup.
>
> From a profile of system checks on a smaller project, there were ~1k
> calls for various versions of each method:
>
> {{{
> 630 0.000 0.000 0.000 0.000
> __init__.py:976(get_attname_column)
> 208 0.000 0.000 0.000 0.000
> related.py:1122(get_attname_column)
> 431 0.000 0.000 0.000 0.000 related.py:1119(get_attname)
> 666 0.000 0.000 0.000 0.000 __init__.py:973(get_attname)
> }}}
>
> All of these are eliminated by moving to attribute access.
New description:
Many field references call `Field.get_attname_column()` or
`Field.get_attname()`, despite the `attname` and `column` attributes
containing the computed results (after `contribute_to_class()`). Updating
those call sites to plain attribute access eliminates some function calls,
a worthy small speedup.
From a profile of system checks on a smaller project, there were ~2k calls
between the versions of each method:
* 630 for `Field.get_attname_column()`
* 208 for `ForeignKey.get_attname_column()`
* 666 for `Field.get_attname()`
* 431 for `ForeignKey.get_attname()`
All of these are eliminated by moving to attribute access.
--
--
Ticket URL: <
https://code.djangoproject.com/ticket/35236#comment:1>