Edit this page

NA-MIC Project Weeks

Back to Projects List

Optimizing Bundle Size of PolySeg-WASM for Web Applications

Key Investigators

Presenter location: Online

Project Description

The Institute of Cancer Research (ICR) has created PolySeg-WASM is an extended WASM wrapper for the PerkLab/PolySeg library, including C++ code repurposed from Slicer and SlicerRT.

In the previous year project we created the contour segmentation representation for Cornerstone3D library, now this year we want to use the polySEG to convert the contours to closed surfaces.

The repo by ICR does the job However, the bundle is huge (3.6MB) which is not optimal for the web applications. This project aims to find out how to reduce the bundle size by choosing the VTK dependencies.

Objective

  1. Analyze VTK dependencies: dentify the specific VTK components used in the PolySeg-WASM library that contribute the most to the bundle size in order to determine areas for potential optimization.
  2. Optimize VTK bundle size: Reduce the bundle size of PolySeg-WASM by selectively choosing essential VTK dependencies, excluding or replacing components with lightweight alternatives, while maintaining the required functionality.
  3. Evaluate performance and functionality: Assess the performance and functionality of the optimized PolySeg-WASM library to ensure that the reduction in bundle size does not compromise accuracy or efficiency in converting contours to closed surfaces for web applications.

Approach and Plan

  1. Perform a detailed code analysis to identify the specific VTK components used in PolySeg-WASM.
  2. Measure the size contribution of each VTK component to the overall bundle size of PolySeg-WASM.
  3. Document the findings, including a breakdown of the size contribution of each component.

Progress and Next Steps

  1. Updated the vtk that polyseg-wasm is using to the one that slicer is using which is specified here, it was previously depending on latest vtk
  2. We initially tried to reduce the final wasm size by disabling various modules in the vtk cmake. However, this approach didn’t yield the desired results.
  3. Next, we examined the polySEG-wasm’s cmake to determine potential modifications for size reduction. We discovered that all vtk dependencies are included in ${VTK_LIBS}, set by cmake. By incrementally adding these dependencies, we pinpointed the minimum number of libraries needed, resulting in a 550 KB reduction in the final wasm size. The final set of included libraries was VTK::CommonDataModel VTK::CommonCore VTK::CommonExecutionModel VTK::FiltersCore VTK::FiltersExtraction VTK::ImagingStencil VTK::ImagingStatistics VTK::ImagingMorphological.
  4. Furthermore, we observed that the browser gzips the loaded wasm, bringing the final resource size down to 800 KB - a significant improvement from before.
  5. PR created here

Next steps

  1. We should look into if we can even narrow down even more the VTK::CommonDataModel and VTK::CommonCore to only include those sub libs that is necessary for the build

Illustrations

image

image

Background and References

PolySEG repo ICR Wrapper