From bed2708bd533f803b4ae04ea4ca52828a28e246a Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Wed, 13 Mar 2024 17:40:57 +0530 Subject: [PATCH] perf: rendering large data (#197) visibleRowIndices.includes is major culprit in rendering data table. This is because for every row it does this computation, so instead of O(N) operation it becomes O(N^2) --- src/body-renderer.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/body-renderer.js b/src/body-renderer.js index 1e05aab..ebc0daa 100644 --- a/src/body-renderer.js +++ b/src/body-renderer.js @@ -21,8 +21,11 @@ export default class BodyRenderer { return; } + // Create a temporary set for faster lookups. + // We can't change this.visibleRowIndices as it would be breaking for users. + let visibleRowIndicesSet = new Set(this.visibleRowIndices); const rowViewOrder = this.datamanager.rowViewOrder.map(index => { - if (this.visibleRowIndices.includes(index)) { + if (visibleRowIndicesSet.has(index)) { return index; } return null;