# Slowly rendering widget from 3D Slicer in wasm.

**URL:** https://discourse.vtk.org/t/slowly-rendering-widget-from-3d-slicer-in-wasm/11778
**Category:** Web
**Tags:** vtkwasm
**Created:** [June 21, 2023, 3:03am UTC](https://discourse.vtk.org/t/slowly-rendering-widget-from-3d-slicer-in-wasm/11778 "2023-06-21T03:03:38Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![mazurkin.daniel](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mazurkin.daniel/32/7277_2.png) [@mazurkin.daniel](https://discourse.vtk.org/u/mazurkin.daniel)
#### Post date: [June 21, 2023, 3:03am UTC](https://discourse.vtk.org/t/slowly-rendering-widget-from-3d-slicer-in-wasm/11778/1 "2023-06-21T03:03:38Z")

</div>

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](https://docs.google.com/document/d/1dXtK01DpxkANEJEbvwo1Dnph-B_XpNmor3kCTDFklp0/edit)), 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](https://kitware.github.io/vtk-js/examples/TubeFilter.html) works correctly on vtk.js. 3D Slicer uses vtkTubeFilter under the hood.

 ![image](https://discourse.vtk.org/uploads/default/original/2X/7/78400573fe3940a14b7c30d6750373bf47cca4c9.png)

---

<div class="post-metadata">

### Author: ![Forrest](https://discourse.vtk.org/user_avatar/discourse.vtk.org/forrest/32/300_2.png) [@Forrest](https://discourse.vtk.org/u/Forrest)
#### Post date: [June 22, 2023, 7:24pm UTC](https://discourse.vtk.org/t/slowly-rendering-widget-from-3d-slicer-in-wasm/11778/2 "2023-06-22T19:24:29Z")

</div>

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

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [July 14, 2023, 2:33pm UTC](https://discourse.vtk.org/t/slowly-rendering-widget-from-3d-slicer-in-wasm/11778/3 "2023-07-14T14:33:40Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![mazurkin.daniel](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mazurkin.daniel/32/7277_2.png) [@mazurkin.daniel](https://discourse.vtk.org/u/mazurkin.daniel)
#### Post date: [July 28, 2023, 2:07am UTC](https://discourse.vtk.org/t/slowly-rendering-widget-from-3d-slicer-in-wasm/11778/4 "2023-07-28T02:07:52Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [July 28, 2023, 1:59pm UTC](https://discourse.vtk.org/t/slowly-rendering-widget-from-3d-slicer-in-wasm/11778/5 "2023-07-28T13:59:15Z")

</div>

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](https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/WebGL_best_practices#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](https://www.kitware.com/vtk-webgpu-on-the-desktop/) 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!
