mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-11 16:26:20 +00:00
Loop through Wasm re-init for issue repro
This commit is contained in:
@@ -54,7 +54,12 @@ async function startMainThread() {
|
||||
|
||||
return {
|
||||
optimise,
|
||||
freeWorkers: () => {
|
||||
for (const worker of resolvedWorkers) {
|
||||
worker.terminate();
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default startMainThread();
|
||||
export default () => startMainThread();
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
// @ts-ignore
|
||||
import optimiser from '../../../codecs/oxipng';
|
||||
import init from '../../../codecs/oxipng/spawn';
|
||||
import { EncodeOptions } from './encoder-meta';
|
||||
|
||||
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