Opened 8 months ago
Closed 8 months ago
#35266 closed Cleanup/optimization (fixed)
Optimize RelatedField._check_clashes()
Reported by: | Adam Johnson | Owned by: | Adam Johnson |
---|---|---|---|
Component: | Core (System checks) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Continuing my project to optimize the system checks, I found some easy optimizations in RelatedField._check_clashes(), which I found to take 6% of the total runtime for checks.
The function was formatting strings for error messages for each potential clash. This formatting is wasted when there is no error, which is the typical case. Moreover, the cost is exacerbated due to using the Model._meta.label
property, invoking a function call.
Pushing the formatting to error cases speeds up the function significantly. I found this method was called 228 times during system checks for a project with 118 models, taking 4ms or 6% of the total total runtime. After optimizing, the cost is reduced to 1ms, or ~1.5%.
Change History (3)
comment:1 by , 8 months ago
Has patch: | set |
---|---|
Owner: | changed from | to
Status: | new → assigned |
comment:2 by , 8 months ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 8 months ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
In ab22b7c: