Opened 9 years ago

Closed 9 years ago

#3438 closed (fixed)

django.db.models.base.__init__ refactoring

Reported by: (removed) Owned by: adrian
Component: Core (Other) Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation:
Needs tests: Patch needs improvement:
Easy pickings: UI/UX:

Description

Short version; for iteration over records, there model's init is rather unfriendly to the way the args are passed in.

At least for sqlite, the sql row is passed in as args- issue is that init shoots through self._model.fields playing with kwargs prior, doing rather costly exception catching, pulling default values, etc, then *finally* does args processing.

If you're dealing in one or two records, this doesn't show up much, but if you're dealing in 53k records (my usage is slightly weird admittedly), it's a pretty heavy slow down.

attached is a patch to refactor init, knocking around a third off the init cost via refactoring the args/kwargs processing, essentially reversing the actual flow while maintaining the same behaviour as before.

Have been using it for a few days, and passes tests; comments welcome, mainly since I need to get this integrated for my uses.

Attachments (1)

models-init.patch (5.5 KB) - added by (removed) 9 years ago.
django.db.models.base.Model.init refactoring

Download all attachments as: .zip

Change History (2)

Changed 9 years ago by (removed)

django.db.models.base.Model.init refactoring

comment:1 Changed 9 years ago by jacob

  • Resolution set to fixed
  • Status changed from new to closed

(In [4597]) Fixed #3438: improved the speed of Model.init (about 1/3 faster, it appears). Thanks (a lot!) to Brian Harring.

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