diff options
| author | Xavier Morel <xmo@odoo.com> | 2018-08-17 16:16:13 +0200 |
|---|---|---|
| committer | xmo-odoo <xmo@odoo.com> | 2018-09-11 16:43:55 +0200 |
| commit | c3216db4c14ac9a34d798de087797192fe2dec35 (patch) | |
| tree | 9966d95dd004a89e1e3e7a09b4d808abb965461b /odoo/api.py | |
| parent | 08ce84f51d736a992a5c57aafa386d8932e0f675 (diff) | |
[IMP] fields: performance of creating with m2m fields
Note: all costs are according to cprofile on my machine, as a fraction
of total time to import, python-flamegraph has somewhat different cost
distributions, YMMV. Profiles use test-import of a 2500 partners file,
with name, country, street and 0~4 tags, all randomly
generated/assigned.
Costs were profiled as split 8.5%/32%/57% between data conversion,
creating records (Model.create/Model._create) and populating stored
computed fields for a total import time (unprofiled) of 1mn (±2s or
something).
For the creation step, 27% (of total runtime) were assigned to the m2m
(fields.Many2many.create), almost all of which (25%) was assigned to
accessing a record's id in a listcomp in a loop.
Optimisations:
* optimise the case where we're only adding / creating values:
represent the relation as a dict of sets instead of a set of pairs;
commands 5 and 6 will only operate on the current record's value,
instead of traversing all pairs in the relation
* optimise accessing the value of an id field by hand-inlining the
various bits, this is mostly obviated by the other previous
optimisations (number of Id.__get__ calls reduced from 5.4 millions
to 0.55) but given how common accessing a record's id is (and
how it's usually considered to be free) it's still a good idea: cost
of accessing the id field was reduced by 75% (0.55 million accesses
went from 3.32% of total runtime to 0.83%)
Without profiling, time to import my test file went from ~1mn to ~45s.
Diffstat (limited to 'odoo/api.py')
0 files changed, 0 insertions, 0 deletions
