question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improving Performance by reusing graphics objects

See original GitHub issue

Hi 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:

  1. Would calling of removeChild whenever addChild is called would slow the performance?
  2. 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.
  3. 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:closed
  • Created 2 years ago
  • Comments:20 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
krnbattacommented, Aug 28, 2021

P.S. Obligatory comment after this was asked for 100 times. If you want complete explanation with all the code of possible ways - sponsor a book. If you want just simple API - sponsor the plugin.

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 😃

1reaction
ivanpopelyshevcommented, Aug 26, 2021

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

  1. children is array. You know how splice works? Then you can estimate it.
  2. to have separate… what? what do you mean context? Containers exists to apply their transforms to children and to add/remove elements at the same time.
  3. Many. Choosing particular optimization means you already know where your bottleneck is and how new algorithm works. so, whats your bottleneck?
Read more comments on GitHub >

github_iconTop Results From Across the Web

Object Reuse - Java Performance Tuning [Book] - O'Reilly
Recycling these types of objects can certainly improve performance. Recycling can also apply to the internal elements of structures. For example, a linked...
Read more >
Performance Tuning Object Graphics - L3HarrisGeospatial.com
In general, such accelerators will provide better rendering performance for many object graphics displays. This is typically true for images rendered using ...
Read more >
Graphics Performance Improvements - Oracle
The process of creating and disposing of Graphics objects is also faster as a result of the general pipeline improvements. Since each subcomponent...
Read more >
How Object Reuse Can Reduce Latency and Improve ...
Carefully reusing objects provides a way to maintain performance while keeping most parts of the intended level of abstraction. This article explores several ......
Read more >
Optimizing graphics performance - Unity - Manual
Good performance is critical to the success of many games. Below are some simple guidelines for maximizing the speed of your game's rendering....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found