WebGPUEngine initAsync function is slow

Here is the code to initialize the engine,

console.time("createEngine");
    const webGPUSupported = await WebGPUEngine.IsSupportedAsync;
    console.timeEnd("createEngine");
    if (webGPUSupported) {
      const engine = new WebGPUEngine(this.canvas);
      console.time("initAsync");
      await engine.initAsync();
      console.timeEnd("initAsync");
      return engine;
    }
    return new Engine(this.canvas, true, this._option);

Result:

createEngine: 120.93310546875 ms
logger.js:49 BJS - [10:07:08]: Babylon.js v6.2.0 - WebGPU1 engine
index.ts:39 initAsync: 2567.6669921875 ms

u could possibly shave a little time by doing something like

return (navigator.gpu && await new WebGPUEngine(this.canvas).initAsync ) || new Engine(this.canvas, true, this._option);

the logical or will shortcut and never be evaluated, whereas in ur current one, v8 will prep both branches.

But, one thing to consider is that webgpu and vulkan in general requires you to declare and compile stuff up front, so i think longer init time is probably unavoidable.

Also, the webgpu engine comes with twgsl, and idk if that done sequentially after calling init, but if it is, you’ll be network bound and could benefit from packaging it locally.

2 Likes

Yes, most of the time is probably spent downloading TWGSL, which is part of the initialization process.