Improving Performance by reusing graphics objects
See original GitHub issueHi I am using Pixi.js to visualise pathfinding algorithms. Link: https://pf-algo-viz.org/ Now this involves drawing lot of similar graphics objects(circle, rectangle, etc) at same position(with different colours). Currently, I am generating a new graphics objects against each node. To optimise this, I am thinking of reusing the graphics objects at same position and only changing its attributes. This would ensure that fewer graphics objects are created. But the problem is as per current implementation, each node has graphics container which in turn has children(rectangles, circles, lines, etc) If I reuse the graphics object in another node’s graphics container, it would first remove it from the previous container(since pixi objects can only stay at one place - looked into source code).
I am confused whether to use different container for different nodes or just add everything in stage and update attributes(colours, borders) of graphic objects(rectangle, circle) there since then, I won’t be using addChild
and only updating attributes of existing object. This would decrease maintainability of the code. But I think this would significantly improve performance. I have following questions:
- Would calling of
removeChild
wheneveraddChild
is called would slow the performance? - I read that it is better to use containers to have separate context. Should I continue keeping separate containers for each node or just draw everything on one main canvas? I want to avoid this as this would cause serious refactoring of project.
- Are there other ways in which I can improve the performance like reusing texture or anything else?
I would really appreciate suggestions for improving performance.
P.S. This is an open-source project. Please feel free to look into it.
Issue Analytics
- State:
- Created 2 years ago
- Comments:20 (6 by maintainers)
Top GitHub Comments
I really liked PIXI.js and you guys support. I don’t understand graphics much but still trying to wrap my head around. I am donating to PIXI. This is the first time I have ever donated to any open source project 😃
We are working on ability to make any regular shapes (circles, stars, e.t.c.) like sprites, with same performance. You can assign a bounty on that task , like it was done with https://github.com/pixijs/pixijs/issues/7511
children
is array. You know howsplice
works? Then you can estimate it.