Skip to content

Commit

Permalink
[FIX] performance: rtree comparer
Browse files Browse the repository at this point in the history
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: #3679
  • Loading branch information
VincentSchippefilt committed Feb 13, 2024
1 parent 192dc81 commit 7a0dafc
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/plugins/ui_core_views/cell_evaluation/r_tree.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import RBush from "rbush";

import { deepEquals } from "../../../helpers";
import { UID, Zone } from "../../../types";

/**
Expand Down Expand Up @@ -128,7 +127,18 @@ export class SpreadsheetRTree<T> {
if (!this.rTrees[sheetId]) {
return;
}
this.rTrees[sheetId].remove(item, deepEquals);
this.rTrees[sheetId].remove(item, this.rtreeItemComparer);
}

rtreeItemComparer(left: RTreeItem<T>, right: RTreeItem<T>) {
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
);
}
}

Expand Down

0 comments on commit 7a0dafc

Please sign in to comment.