Opened 88 minutes ago

Last modified 7 minutes ago

#36987 assigned Cleanup/optimization

UUIDField.get_db_prep_value does not observe prepared argument

Reported by: Jacob Walls Owned by: Jacob Walls
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Aarni Koskela, Tim Graham, Simon Charette Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Jacob Walls)

The doc'd "default" pattern for fields is for get_db_prep_value() to call the get_prep_value() method if prepared is False. The idea being, I assume, to avoid wasted computation if the value is already prepared=True.

UUIDField doesn't follow this pattern, causing two extra calls to isinstance(val, UUID) per value, which can add up for a large bag of values, e.g. a prefetch_related() call.

Here is a fiddle on DryORM with my fix branch checked out. Re-run the fiddle against main and notice 4 more calls to isinstance (2 * n objects).

Discovered while reviewing the profile in a micro-optimization PR


I acknowledge there is some exploratory effort toward removing this argument in a draft PR.

Change History (3)

comment:1 by Jacob Walls, 84 minutes ago

comment:2 by Jacob Walls, 84 minutes ago

Description: modified (diff)

comment:3 by Simon Charette, 7 minutes ago

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