Opened 3 months ago

Closed 3 months ago

#35236 closed Cleanup/optimization (fixed)

Access Field.attname and Field.column directly

Reported by: Adam Johnson Owned by: Adam Johnson
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Adam Johnson)

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.

Change History (6)

comment:1 by Adam Johnson, 3 months ago

Description: modified (diff)
Has patch: set
Owner: changed from nobody to Adam Johnson

comment:2 by Mariusz Felisiak, 3 months ago

I'm pretty sure this will break some 3rd party packages, e.g.django-joinfield. I don't think it's worth doing.

comment:3 by Adam Johnson, 3 months ago

I think it has very little chance to break things. There are hundreds of pre-existing uses of .attname and .column, the PR only updates a handful. Also, non-deterministic attname would be somewhat meaningless, as nothing would reattach the field’s descriptor with a different attribute name.

comment:4 by Mariusz Felisiak, 3 months ago

Triage Stage: UnreviewedAccepted

I'm always preoccupied with such cleanups as more often than not they cause regressions, but agreed, let's give it a chance.

comment:5 by Mariusz Felisiak, 3 months ago

Triage Stage: AcceptedReady for checkin

comment:6 by Mariusz Felisiak <felisiak.mariusz@…>, 3 months ago

Resolution: fixed
Status: assignedclosed

In 31314980:

Fixed #35236 -- Used Field.attname/column attributes instead of get_attname()/get_attname_column().

Note: See TracTickets for help on using tickets.
Back to Top