Slowly rendering widget from 3D Slicer in wasm.

Hello, I have built a widget display from 3D Slicer in WebAssembly (you can check out the instructions at this link Instruction by 3dSlicer - Google Docs), but when rendering, it all happens quite slowly. Can you please suggest what could be the reason? Just to provide a direction for investigations, because for example, vtk.js works correctly on vtk.js. 3D Slicer uses vtkTubeFilter under the hood.

I’d start with checking the devtools performance profile to see what tasks are causing a slow render.

If rendering is slow for single line, I suspect your dev console is getting choked with error logs coming from the rendering stack. Usual suspect because glGetError will block for error message retreival. Are you sure your dev console is clean?

Better performance was achieved by a change in the behavior of the ReadPixel function, but we decided to temporarily move away from the 3D Slicer approach to forming tools due to the large number of errors and unpredictable situations associated with the web browser and graphics.

Yup, glReadPixels is known to block for absurd amounts of time. The fact is VTK uses blocking OpenGL calls even in production. We could restructure VTK read pixels to use pixel buffer objects as recommended by MDN: Avoid blocking API calls in production

but we decided to temporarily move away from the 3D Slicer approach to forming tools due to the large number of errors and unpredictable situations associated with the web browser and graphics.

With the new webgpu backend, we can resort to faster techniques that read pixels asynchronously without stalls in the render pipeline and report human-comprehensible error messages instead of cryptic GL error codes. VTK data processing is at a very mature stage and uses the latest technologies of the era. That’s not the case with VTK raster graphics.

We’re working on advancing VTK graphics to be on par with modern expectations of a graphics engine/library! If you are interested in helping with code or project opportunities by colloaborating with Kitware, the VTK community would welcome your contributions!