From 7a0dafc33936aa9f4b5910dcc485852699d5af36 Mon Sep 17 00:00:00 2001 From: Vincent Schippefilt Date: Tue, 13 Feb 2024 09:36:06 +0100 Subject: [PATCH] [FIX] performance: rtree comparer using a set in deepEqual is very slow. in rtrees, we know exactly the data structure that we are using so building a specific comparer for this data structure makes sense. Part-of: odoo/o-spreadsheet#3679 --- .../ui_core_views/cell_evaluation/r_tree.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/plugins/ui_core_views/cell_evaluation/r_tree.ts b/src/plugins/ui_core_views/cell_evaluation/r_tree.ts index 63c9e59e08..22f8163a96 100644 --- a/src/plugins/ui_core_views/cell_evaluation/r_tree.ts +++ b/src/plugins/ui_core_views/cell_evaluation/r_tree.ts @@ -1,6 +1,5 @@ import RBush from "rbush"; -import { deepEquals } from "../../../helpers"; import { UID, Zone } from "../../../types"; /** @@ -128,7 +127,18 @@ export class SpreadsheetRTree { if (!this.rTrees[sheetId]) { return; } - this.rTrees[sheetId].remove(item, deepEquals); + this.rTrees[sheetId].remove(item, this.rtreeItemComparer); + } + + rtreeItemComparer(left: RTreeItem, right: RTreeItem) { + return ( + left.data == right.data && + left.boundingBox.sheetId === right.boundingBox.sheetId && + left.boundingBox?.zone.left === right.boundingBox.zone.left && + left.boundingBox?.zone.top === right.boundingBox.zone.top && + left.boundingBox?.zone.right === right.boundingBox.zone.right && + left.boundingBox?.zone.bottom === right.boundingBox.zone.bottom + ); } }