Opened 17 years ago

Closed 17 years ago

#3438 closed (fixed)

django.db.models.base.__init__ refactoring

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

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) 17 years ago.
django.db.models.base.Model.init refactoring

Download all attachments as: .zip

Change History (2)

by (removed), 17 years ago

Attachment: models-init.patch added

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

comment:1 by Jacob, 17 years ago

Resolution: fixed
Status: newclosed

(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