-
-
Notifications
You must be signed in to change notification settings - Fork 79
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
drawImage performance bug with canvas #972
Comments
ran benchmark on my mac pro 14 M2 Max 64G
then added a canvas on canvas draw to both tests: // start of drawGradient() and drawHouse()
const canvas = factory(1024, 768)
const canvas2 = factory(1920, 1080)
const ctx = canvas.getContext('2d')!
const ctx2 = canvas2.getContext('2d')!
// the test's canvas drawing commands
// draw the canvas on a canvas
ctx2.drawImage(canvas, 0, 0, canvas2.width, canvas2.height)
// rest of test
drops to about 62 to 65 % of skia-canvas performance |
performance issue still present after 0.1.67 This is with my change to the benchmark above to draw canvas on canvas:
@Brooooooklyn can this issue be re-opened? |
@monteslu I found that your measurement is false positive, |
Can confirm the Skia-canvas draw_image: https://github.com/samizdatco/skia-canvas/blob/v2.0.2/src/context/mod.rs#L478 |
Ahh, that would explain why skia-canvas appears to be faster. For some reference, I'm using this library along with https://github.com/kmamal/node-sdl to enable canvas based games on devices that don't have enough ram to run chrome. I'm not actually creating image files or streams. //... do drawing commands with @napi-rs/canvas including canvas-on-canvas drawing
// get buffer from canvas.
const buffer = Buffer.from(backCanvas.data().buffer);
// libSDL window
appWindow.render(backCanvas.width, backCanvas.height, stride, 'rgba32', buffer); 0.1.65 and 0.1.67 correctly stretch/render to the underlying buffer. They're just significantly slower than canvas-on-canvas rendering in chrome or firefox. This is the library I'm working on that uses @napi-rs/canvas and SDL: https://github.com/monteslu/jsgamelauncher Here's a video that explains the js gamelauncher a little more: https://www.youtube.com/watch?v=osJsBRPSrM4 |
Since I can get the canvas.data().buffer() really quickly and drawImage() with an Image seems to be a fast operation, Is there any way I can create an Image object with the data buffer directly? Maybe I can work around that casting operation. |
Drawing a canvas onto a canvas is almost 8 times slower than drawing an image onto a canvas:
outputs:
average draw image time 1.2156541699999999
average draw canvas time 8.897838329999999
On the web the two draw in about the same amount of time. 7 milliseconds can make a huge amount of difference when you might have a 16 millisecond budget rendering at 60Hz.
My stab in the dark guess is that somewhere along the way there's a mem copy happening.
Something similar to:
Buffer.from(imageData.data.buffer))
vsBuffer.from(imageData.data))
The text was updated successfully, but these errors were encountered: