From 06b88cda20ce064d1434bc563733073abdc22984 Mon Sep 17 00:00:00 2001 From: Bruce Martin Date: Mon, 9 Nov 2020 10:41:39 -0800 Subject: [PATCH] do not update GPU buffers if data has not changed (#1967) Co-authored-by: maniarathi Co-authored-by: Severiano Badajoz --- client/src/components/graph/graph.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/client/src/components/graph/graph.js b/client/src/components/graph/graph.js index 7ec11976..f2466b4d 100644 --- a/client/src/components/graph/graph.js +++ b/client/src/components/graph/graph.js @@ -730,14 +730,25 @@ class Graph extends React.Component { ); }); - updateReglAndRender(asyncProps) { + updateReglAndRender(asyncProps, prevAsyncProps) { const { positions, colors, flags } = asyncProps; this.cachedAsyncProps = asyncProps; const { pointBuffer, colorBuffer, flagBuffer } = this.state; - pointBuffer({ data: positions, dimension: 2 }); - colorBuffer({ data: colors, dimension: 3 }); - flagBuffer({ data: flags, dimension: 1 }); - this.renderCanvas(); + let needToRenderCanvas = false; + + if (positions !== prevAsyncProps?.positions) { + pointBuffer({ data: positions, dimension: 2 }); + needToRenderCanvas = true; + } + if (colors !== prevAsyncProps?.colors) { + colorBuffer({ data: colors, dimension: 3 }); + needToRenderCanvas = true; + } + if (flags !== prevAsyncProps?.flags) { + flagBuffer({ data: flags, dimension: 1 }); + needToRenderCanvas = true; + } + if (needToRenderCanvas) this.renderCanvas(); } updateColorTable(colors, colorDf) { @@ -906,7 +917,7 @@ class Graph extends React.Component { {(asyncProps) => { if (regl && !shallowEqual(asyncProps, this.cachedAsyncProps)) { - this.updateReglAndRender(asyncProps); + this.updateReglAndRender(asyncProps, this.cachedAsyncProps); } return null; }}