Opened 4 hours ago

Last modified 3 hours ago

#36987 assigned Cleanup/optimization

UUIDField.get_db_prep_value does not observe prepared argument — at Initial Version

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

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 fewer 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 (0)

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