fix: use cpu for skia-canvas rendering (#2334)

Seems there's a memory leak in gpu rendering with skia canvas
where contexts can live for much longer than expected escaping gc
cleanup

CPU rendering seems better albeit a bit slower.

Synthetic tests were ran with `--expose-gc` to simulate load over time.
This commit is contained in:
Lucas Smith
2025-12-17 14:48:21 +11:00
committed by GitHub
parent a5e5eecf8b
commit 6739242554
+6 -1
View File
@@ -9,7 +9,10 @@ globalThis.Image = Image;
class SkiaCanvasFactory {
_createCanvas(width: number, height: number) {
return new Canvas(width, height);
const canvas = new Canvas(width, height);
canvas.gpu = false;
return canvas;
}
create(width: number, height: number) {
@@ -60,6 +63,8 @@ export const pdfToImages = async (pdfBytes: Uint8Array, options: PdfToImagesOpti
const viewport = page.getViewport({ scale });
const canvas = new Canvas(viewport.width, viewport.height);
canvas.gpu = false;
const canvasContext = canvas.getContext('2d');
await page.render({