summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/model/model_manager.js
diff options
context:
space:
mode:
authorSébastien Theys <seb@odoo.com>2020-07-30 16:14:32 +0000
committerSébastien Theys <seb@odoo.com>2020-07-31 09:43:01 +0000
commit78bef3e08c04a45bdf9122e595160e42bf7af8e1 (patch)
treee606c67646a48907979f9927438bc9691b2e6cd3 /addons/mail/static/src/model/model_manager.js
parent89bf21ba797d72ff624fbf88e97a40628f72e0d8 (diff)
[FIX] mail: improve performance of JS write, especially for x2m
- store `x2many` values as `Set`. This is conceptually more correct because duplicates were already not allowed, and using a `Set` allows for much faster operations such as checking the presence of a record in the relation, which is done at every write, for every linked record. - `stringify` in `write` was slow and unnecessary because we can always assume that new non-primitive should be provided to `write` - remove field values from store, in favor of just storing a counter, which is enough to trigger renders. This allows to get rid of one Proxy level around data, which was slower, but which also prevented from using `Set`. - write in store exactly once per update cycle, to trigger one `useStore` call on each component. Records keep `__state` but as a local counter, to let `useStore` know which records have been updated (easier to compare a counter than comparing each and every field value). Results ======= The worse case test (using a lot of x2m) that was used to benchmark this PR `form_renderer_tests.js` of `mail_enterprise` went from taking around 4s before this commit, to around 2.5s after this commit. And the worse `_setRelationLinkMany2Many` previously took around 250ms, and it now takes around 50ms. The whole `mail` QUnit suite took around 55s before, now around 42s. Part of task-2308312 closes odoo/odoo#55248 X-original-commit: 4db0a10d85534ef896f6bcbf13bca4983a6e2003 Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Diffstat (limited to 'addons/mail/static/src/model/model_manager.js')
-rw-r--r--addons/mail/static/src/model/model_manager.js15
1 files changed, 8 insertions, 7 deletions
diff --git a/addons/mail/static/src/model/model_manager.js b/addons/mail/static/src/model/model_manager.js
index 37ce2d2808c..5ef0d5c19ae 100644
--- a/addons/mail/static/src/model/model_manager.js
+++ b/addons/mail/static/src/model/model_manager.js
@@ -122,11 +122,10 @@ class ModelManager {
const record = new Model({ valid: true });
Object.defineProperty(record, 'env', { get: () => Model.env });
record.localId = record._createRecordLocalId(data);
-
- // Make state, which contain field values of record that have to
- // be observed in store.
- this.env.store.state[record.localId] = {};
- record.__state = this.env.store.state[record.localId];
+ // Contains field values of record.
+ record.__values = {};
+ // Contains revNumber of record for checking record update in useStore.
+ record.__state = 0;
// Make proxified record, so that access to field redirects
// to field getter.
@@ -299,6 +298,8 @@ class ModelManager {
}
this._toComputeFields.clear();
this._isInUpdateCycle = false;
+ // trigger at most one useStore call per update cycle
+ this.env.store.state.messagingRevNumber++;
} else {
this._updateDirect(record, data);
if (this._isHandlingToUpdateAfters) {
@@ -689,8 +690,8 @@ class ModelManager {
}
if (field.fieldType === 'relation') {
if (['one2many', 'many2many'].includes(field.relationType)) {
- // Ensure X2many relations are arrays by defaults.
- field.write(record, [], { registerDependents: false });
+ // Ensure X2many relations are Set by defaults.
+ field.write(record, new Set(), { registerDependents: false });
} else {
field.write(record, undefined, { registerDependents: false });
}