#35266: Optimize RelatedField._check_clashes()
------------------------------------------------+------------------------
               Reporter:  Adam Johnson          |          Owner:  nobody
                   Type:  Cleanup/optimization  |         Status:  new
              Component:  Core (System checks)  |        Version:  dev
               Severity:  Normal                |       Keywords:
           Triage Stage:  Unreviewed            |      Has patch:  0
    Needs documentation:  0                     |    Needs tests:  0
Patch needs improvement:  0                     |  Easy pickings:  0
                  UI/UX:  0                     |
------------------------------------------------+------------------------
 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%.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35266>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018e0688b414-bb1463a2-bb6a-4bed-815a-9012c90ef542-000000%40eu-central-1.amazonses.com.

Reply via email to