#36815: Avoid unnecessary prepare_value calls when inserting db_defaults
-------------------------------------+-------------------------------------
     Reporter:  Adam Sołtysik        |                     Type:
                                     |  Cleanup/optimization
       Status:  new                  |                Component:  Database
                                     |  layer (models, ORM)
      Version:  6.0                  |                 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
-------------------------------------+-------------------------------------
 In `SQLInsertCompiler.as_sql`, it looks like `prepare_value` is
 unnecessarily called for each `DatabaseDefault` value on every inserted
 object. These calls are quite expensive (as they enter the `if
 hasattr(value, "resolve_expression")` branch) and waste a lot of time when
 using `bulk_create`.

 I've written a potential patch and a simple benchmark:
 
https://github.com/adamsol/django/commit/d6f275c8960988c92a9da5eb323b6bd6fc7717cb.
 The benchmark runs 2x faster with the fix, even though there's only one
 field with `db_default` in that model. The difference may become larger
 with more fields.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36815>
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 visit 
https://groups.google.com/d/msgid/django-updates/0107019b3c433d56-421755d6-9561-4619-897b-41209854b806-000000%40eu-central-1.amazonses.com.

Reply via email to