mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-16 18:49:50 +00:00
[temporary] More reliable issue repro
This commit is contained in:
@@ -19,7 +19,10 @@ async function startMainThread() {
|
||||
|
||||
// First, let browser fetch and spawn Workers for our pool in the background.
|
||||
// This is fairly expensive, so we want to start it as early as possible.
|
||||
const workers = Array.from({ length: num }, () => new Worker('./worker', { type: 'module' }));
|
||||
const workers = Array.from({ length: num }, () => new Promise<Worker>((resolve) => {
|
||||
const w = new Worker('./worker', { type: 'module' });
|
||||
w.addEventListener('message', () => resolve(w), { once: true });
|
||||
}));
|
||||
|
||||
// Meanwhile, asynchronously compile, instantiate and initialise Wasm on our main thread.
|
||||
await initOxiPNG(fetch(wasmUrl), undefined as any);
|
||||
@@ -38,7 +41,12 @@ async function startMainThread() {
|
||||
// If we didn't do this ping-pong game, the `start_main_thread` below would block the current
|
||||
// thread on an atomic before even *sending* the `postMessage` containing memory,
|
||||
// so Workers would never be able to unblock us back.
|
||||
await Promise.all(workers.map(worker => initWorker(worker, workerInit)));
|
||||
|
||||
// TODO: remove this line.
|
||||
// It waits for all workers to be created just to repro a possible V8 bug.
|
||||
const resolvedWorkers = await Promise.all(workers);
|
||||
|
||||
await Promise.all(resolvedWorkers.map(worker => initWorker(worker, workerInit)));
|
||||
|
||||
// Finally, instantiate rayon pool - this will use shared Wasm memory to send tasks to the
|
||||
// Workers and then block until they're all ready.
|
||||
|
||||
@@ -4,6 +4,10 @@ import initOxiPNG, { start_worker_thread } from './pkg-parallel';
|
||||
|
||||
export type WorkerInit = [WebAssembly.Module, WebAssembly.Memory];
|
||||
|
||||
// TODO: remove this line.
|
||||
// It allows main thread to wait for a Worker to be created just to repro a possible V8 bug.
|
||||
postMessage(null);
|
||||
|
||||
addEventListener(
|
||||
'message',
|
||||
async (event) => {
|
||||
|
||||
@@ -232,7 +232,7 @@ export default class Compress extends Component<Props, State> {
|
||||
{
|
||||
latestSettings: {
|
||||
preprocessorState: defaultPreprocessorState,
|
||||
encoderState: { type: mozJPEG.type, options: mozJPEG.defaultOptions },
|
||||
encoderState: { type: oxiPNG.type, options: oxiPNG.defaultOptions },
|
||||
},
|
||||
loadingCounter: 0,
|
||||
loadedCounter: 0,
|
||||
|
||||
Reference in New Issue
Block a user