mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-12 08:47:31 +00:00
Loop through Wasm re-init for issue repro
This commit is contained in:
@@ -54,7 +54,12 @@ async function startMainThread() {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
optimise,
|
optimise,
|
||||||
|
freeWorkers: () => {
|
||||||
|
for (const worker of resolvedWorkers) {
|
||||||
|
worker.terminate();
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default startMainThread();
|
export default () => startMainThread();
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import optimiser from '../../../codecs/oxipng';
|
import init from '../../../codecs/oxipng/spawn';
|
||||||
import { EncodeOptions } from './encoder-meta';
|
import { EncodeOptions } from './encoder-meta';
|
||||||
|
|
||||||
export async function compress(data: ArrayBuffer, options: EncodeOptions): Promise<ArrayBuffer> {
|
export async function compress(data: ArrayBuffer, options: EncodeOptions): Promise<ArrayBuffer> {
|
||||||
return (await optimiser).optimise(new Uint8Array(data), options.level).buffer;
|
for (let i = 0; i < 100; i += 1) {
|
||||||
|
const optimiser = await init();
|
||||||
|
console.log(`Run #${i}: ${optimiser.optimise(new Uint8Array(data), options.level).buffer.byteLength} bytes`);
|
||||||
|
optimiser.freeWorkers();
|
||||||
|
}
|
||||||
|
return (await init()).optimise(new Uint8Array(data), options.level).buffer;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user