Comments (6)
- You have to measure the performance. What exactly is slow? React reconciler? Konva rendering?
- Konva is not ideal for heavy free handle renders, by default Konva re-renders full scene. Usually, it is not very necessary for drawing apps
- Use full power cache. For example, when you finish drawing, you can cache all previous lines, so Konva don't have re-render them again. Or you can convert all lines into bitmap image with external canvas manually.
from react-konva.
So instead of working with memo and so on, would you rather recommend going with the cache?
Do you have a short example, how to work with cache in react?
from react-konva.
So instead of working with memo and so on, would you rather recommend going with the cache?
First, you need to measure what is slow. it doesn't make sense to optimize Konva rendering if React part is slow.
Do you have a short example, how to work with cache in react?
Access node via https://konvajs.org/docs/react/Access_Konva_Nodes.html
Then use Konva mathods for cache.
from react-konva.
Thanks so far. Interestingly, caching the background image (Din A4 paper) made the performance even worse and the image wasn't shown on my iPad anymore.
I guess I will try to measure the performance in a next step.. Currently it feels like whenever I tried to optimize something, I got worse.
Do you think, that a whiteboard app with free drawing on multiple Din A4 size pages is possible with Konva and React in general?
from react-konva.
Without knowing the details, I can't say whether it is really possible or not. Sounds like yes, but may depend on some use cases.
from react-konva.
Nice I followed your advise with caching:
useEffect(() = >{
if (objects.length > 0) {
const obj = objects[objects.length - 1];
const objRef = obj.ref;
if (obj.type === "line") {
let minX = obj.points[0];
let minY = obj.points[1];
let maxX = obj.points[0];
let maxY = obj.points[1];
for (let i = 2; i < obj.points.length; i += 2) {
const x = obj.points[i];
const y = obj.points[i + 1];
if (x < minX) minX = x;
if (y < minY) minY = y;
if (x > maxX) maxX = x;
if (y > maxY) maxY = y;
}
objRef.current.cache({
width: maxX - minX + (obj.strokeWidth * 2),
height: maxY - minY + (obj.strokeWidth * 2),
pixelRatio: 1
});
} else {
objRef.current.cache({
pixelRatio: 1
});
}
}
},
[objects]);
For now it seems to work. I had a big problem with memory exceeding on an iPad. But since I cache every line individually and calculate how big it is, it is better.
Is there a way to know how much space is left in the cache? Do you possibly know some improvement for the cache?
I could imagine something like: clear cache when a line is not visible and don't event render it and re-cache it again when it is visible again, but I couldn't make it work yet.
from react-konva.
Related Issues (20)
- Uncaught TypeError: getImage.crop is not a function
- Shapes with opacity do not correctly apply layer pixelRatio and can appear blurry on zoom in HOT 4
- NextJS: Module not found: Can't resolve 'canvas' HOT 2
- Issue with RTL Text
- Facing the issue now with Next.js 14: HOT 5
- OnTouchStart does not contain touches HOT 1
- getRelativePointerPosition has an offset on x when going fullscreen
- Asynchronous drawing will exceed the cropping area HOT 4
- Transformer is not reusable HOT 2
- Coordinates not working correctly after zoom in/out or drag of stage HOT 1
- If I want to erase only the lines drawn with a pen, how can I do that? HOT 2
- Rendering <Context.Consumer.Provider> is not supported and will be removed in a future major release. HOT 1
- Arrow Drag and Transform using anchors not working HOT 4
- load data to stage HOT 1
- Positioning issue with transformer using keepRatio prop set to false HOT 1
- Breaking changes in React experimental branch
- TypeScript : `'cornerRadius'` does not exist on type `Shape<RectConfig>` HOT 4
- Trouble with Drag-and-Drop on Mobile Devices in React (with react-konva) HOT 1
- g
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-konva.