raaga icon indicating copy to clipboard operation
raaga copied to clipboard

Use a hidden canvas in memory to paint to avoid jank

Open ankeetmaini opened this issue 6 years ago • 7 comments

Screenshot 2019-10-02 at 10 32 40 PM

So I played with this app a bit. To support OffScreenCanvas, I tried using an in-memory canvas (not drawn on the main screen) to draw and copy it to main screen. I think it mostly works, but somehow I see long continuous bars and not exact notes. I'm guessing it's not able to reset the buffer canvas. Attached an image.

Will update this.

ankeetmaini avatar Oct 02 '19 17:10 ankeetmaini

This pull request is being automatically deployed with ZEIT Now (learn more). To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://zeit.co/ritz078/synth/fh28wueo6 🌍 Preview: https://synth-git-fork-ankeetmaini-no-offscreen.ritz078.now.sh

vercel[bot] avatar Oct 02 '19 17:10 vercel[bot]

I think it's okay now, let me know when you've sometime to look at this, I'll remove the hardcodings to always force into non offscreencanvas support.

ankeetmaini avatar Oct 02 '19 17:10 ankeetmaini

You can check the prod build of this PR at https://synth-git-fork-ankeetmaini-no-offscreen.ritz078.now.sh

Let me know if you are not able to open it.

In case you had trouble on opening the app on browsers other than chrome, take a master pull.

ritz078 avatar Oct 02 '19 21:10 ritz078

Our first priority here is making this work on the main thread but in case that doesn't work (highly likely), I think that we can use the same logic in a worker and render on the main canvas after doing the calculations on a offscreen canvas. Might improve the performance even further.

For that we can create a OffscreenCanvas in the worker and do all the rendering on it. after everything for a single frame is done, we can draw the image on the main canvas (whose access we already have in the canvas).

ritz078 avatar Oct 03 '19 16:10 ritz078

I did some profiling, and I think main thread is busy because of something in Keyboard.ts, the profile showed that the browser is doing a lot in terms of recalc and layout too. Will do a deep dive this weekend.

ankeetmaini avatar Oct 04 '19 02:10 ankeetmaini

I'm trying improve the profile perf on this with some trial & error experiments. I'll let you know when this is ready for review.

ankeetmaini avatar Oct 08 '19 03:10 ankeetmaini

sure, take your time.

ritz078 avatar Oct 08 '19 06:10 ritz078