Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Move GC pause voodoo to worker

Manav Rathi5bcf8f9a5873
diff --git a/web/packages/media/heic-convert.ts b/web/packages/media/heic-convert.ts
index 0b44983c09..62cee7ec52 100644
--- a/web/packages/media/heic-convert.ts
+++ b/web/packages/media/heic-convert.ts
@@ -1,5 +1,4 @@
import { ComlinkWorker } from "@/base/worker/comlink-worker";
-import { wait } from "@/utils/promise";
import type { HEICConvertWorker } from "./heic-convert.worker";
/**
@@ -13,11 +12,7 @@ import type { HEICConvertWorker } from "./heic-convert.worker";
* @returns The JPEG blob.
*/
export const heicToJPEG = async (heicBlob: Blob) =>
- worker()
- .then((w) => w.heicToJPEG(heicBlob))
- // I'm told this library used to have big memory spikes, and adding pauses
- // to get GC to run helped.
- .then((res) => wait(10 /* ms */).then(() => res));
+ worker().then((w) => w.heicToJPEG(heicBlob));
/** Cached instance of the {@link ComlinkWorker} that wraps our web worker. */
let _comlinkWorker: ComlinkWorker<typeof HEICConvertWorker> | undefined;
diff --git a/web/packages/media/heic-convert.worker.ts b/web/packages/media/heic-convert.worker.ts
index 5d8383c0a9..52c9d7abba 100644
--- a/web/packages/media/heic-convert.worker.ts
+++ b/web/packages/media/heic-convert.worker.ts
@@ -1,3 +1,4 @@
+import { wait } from "@/utils/promise";
import { expose } from "comlink";
import HeicConvert from "heic-convert";
@@ -8,7 +9,11 @@ export class HEICConvertWorker {
* Both the input and output are blobs.
*/
async heicToJPEG(heicBlob: Blob) {
- return heicToJPEG(heicBlob);
+ const output = await heicToJPEG(heicBlob);
+ // I'm told this library used to have big memory spikes, and adding
+ // pauses to get GC to run helped. This might just be superstition tho.
+ await wait(10 /* ms */);
+ return output;
}
}