Skip to content
Advertisement

React-konva slow drag performance with large number of lines rendered

I have problem with dragging functionality while having large number of rendered lines in React-konva.

Currently I am mapping over Array.apply(null, Array(10000)) to render lines horizontally. However, it is very laggy comparing to dragging over an array of only 500 lines for example.

I have prepared codesandbox to illustrate this issue: https://codesandbox.io/s/dazzling-hooks-0xc4s?file=/src/App.js

(Drag mouse horizontally to see the effect)

Any ideas how to solve this issue will be very appreciated.

Advertisement

Answer

Well, you just have too many shapes. The browser is doing a lot of work, rendering them all. There are many ways to improve Konva performance.

The first approach is to just not render objects that are out of visible viewport:

JavaScript

Demo: https://codesandbox.io/s/react-konva-simple-windowing-render-10000-lines-2hy2u

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement