Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache or optimize triangulation data used for drawing with fill operation #1179

Open
obiot opened this issue Feb 19, 2023 · 0 comments
Open

Comments

@obiot
Copy link
Member

obiot commented Feb 19, 2023

the current Path2d triangulatePath() method :

triangulatePath() {
var i = 0;
var points = this.points;
var vertices = this.vertices;
var indices = earcut(points.flatMap(p => [p.x, p.y]));
// pre-allocate vertices if necessary
while (vertices.length < indices.length) {
vertices.push(pool.pull("Point"));
}
// calculate all vertices
for (i = 0; i < indices.length; i++ ) {
var point = points[indices[i]];
vertices[i].set(point.x, point.y);
}
// recycle overhead from a previous triangulation
while (vertices.length > indices.length) {
pool.push(vertices[vertices.length-1]);
vertices.length -= 1;
}
return vertices;
does not cache the generated data, forcing melonJS to recalculate every thing when using directly method like fillRect() and friends, and create a huge performance bottleneck.

For reference here below is an extract from a benchmark on fill operation for both rectangle and circle:

melonJS 15.0.0 (M1 Max) Fill (rect) Fill (circle)
500 op/s 60 fps 60 fps
1000 op/s 60 fps 32 fps
2500 op/s 35 fps 12 fps
5000 op/s 16 fps 6 fps
10000 op/s 6 fps 4 fps
15000 op/s 4 fps 3 fps

which shows performances dropping when drawing more than 1'000 shapes per frame.

@obiot obiot changed the title Cache or optimize triangulation data use for drawing with fill operation Cache or optimize triangulation data used for drawing with fill operation May 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant