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

2000x slower drawImage #867

Closed
gc opened this issue Aug 9, 2024 · 5 comments · Fixed by #872
Closed

2000x slower drawImage #867

gc opened this issue Aug 9, 2024 · 5 comments · Fixed by #872

Comments

@gc
Copy link

gc commented Aug 9, 2024

drawImage appears to be 2000x slower than other canvas libraries.

The benchmark is drawing lots of parts of a big image (i.e sprites/spritesheets)

NAPI Canvas Average: 2413.62 ms, Min: 2338.18 ms, Max: 2525.64 ms
Node Canvas Average: 0.69 ms, Min: 0.58 ms, Max: 1.05 ms
Skia Canvas Average: 0.72 ms, Min: 0.52 ms, Max: 1.40 ms

Benchmark code https://github.com/gc/canvas-drawimage-benchmark

git clone https://github.com/gc/canvas-drawimage-benchmark.git
cd // yarn // npm install
node index.js
@rambo-panda
Copy link
Contributor

rambo-panda commented Aug 9, 2024

image
image

I temporarily added a console.time, and it shows that @napi-rs/canvas takes a long time on drawImage. I suspect it is related to the pixel copying used in drawImage.

image

@rambo-panda
Copy link
Contributor

In the comparison of the three, the time consumption of drawImage differs the most, with nap-rs/canvas taking as long as 3 seconds. I suspect that the synchronous method is causing "queueing" in the main process.

@gc
Copy link
Author

gc commented Aug 17, 2024

@Brooooooklyn Are you able to publish a new version so I can test? or is there a way I can test without a new version. thanks

@gc
Copy link
Author

gc commented Aug 18, 2024

A big improvement. Thank you

NAPI Canvas Average: 10.68 ms, Min: 8.92 ms, Max: 20.96 ms
Node Canvas Average: 6.31 ms, Min: 5.30 ms, Max: 11.60 ms
Skia Canvas Average: 1.54 ms, Min: 1.35 ms, Max: 19.92 ms

@rambo-panda
Copy link
Contributor

rambo-panda commented Aug 19, 2024

@gc @Brooooooklyn
I found a serious risk of memory leakage during testing.

[129175840.177388] Killed process 11372 (node) total-vm:10889092kB, anon-rss:8374996kB, file-rss:28316kB, shmem-rss:0kB

this is my global env variable NODE_OPTIONS=--max-old-space-size=8192

image

The memory hasn't been released for a long time, even though I regularly execute clearAllCache or global.gc().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants