# getRange/fastComputeRange performance and rendering speed

**URL:** <https://discourse.vtk.org/t/getrange-fastcomputerange-performance-and-rendering-speed/14745>\
**Category:** Development\
**Tags:** vtkjs\
**Created:** [October 21, 2024, 5:32am UTC](https://discourse.vtk.org/t/getrange-fastcomputerange-performance-and-rendering-speed/14745 "2024-10-21T05:32:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Manners](https://discourse.vtk.org/user_avatar/discourse.vtk.org/james_manners/32/9374_2.png) [@James\_Manners](https://discourse.vtk.org/u/James_Manners)\
**Post date:** [October 21, 2024, 5:32am UTC](https://discourse.vtk.org/t/getrange-fastcomputerange-performance-and-rendering-speed/14745/1 "2024-10-21T05:32:31Z")

</div>

Hi,

I have been analysing render performance of CornerstoneJS (which uses vtk.js) with ultrasound cine instances. These instances render many images as a video. You can view an example here [OHIF Viewer](https://viewer.ohif.org/viewer?StudyInstanceUIDs=1.2.840.113663.1500.1.248223208.1.1.20110323.105903.687)

On low-\>mid performance machines, it is very difficult to get smooth playback, particularly with multiple images all rendering at the same time. You can change the layout on the link above to show a grid of 2x2 images and configure them all to play with the cine tool.

Using chrome, I did a performance trace approx 12 seconds, with 4 videos playing. (my machine is a MacBook M1 Pro, so quite high performance). I’ve attached an image of the bottom up call stack showing that approx 50% of all the js event loop is taken up by `fastComputeRange` which is called on each render. The exact call is here in Cornerstone [cornerstone3D/packages/core/src/RenderingEngine/RenderingEngine.ts at main · cornerstonejs/cornerstone3D · GitHub](https://github.com/cornerstonejs/cornerstone3D/blob/main/packages/core/src/RenderingEngine/RenderingEngine.ts#L1173)

 ![Screenshot 2024-10-21 at 4.21.28 pm](https://discourse.vtk.org/uploads/default/original/2X/0/045097d8e229104ed3e4717588c266543963d355.jpeg)

I’m looking to optimise this to help improve performance.

I have 2 thoughts on how to pre-cache the range for each rendered frame:

1. Is it possible to pre-compute the range of the rendered image and pass that into the vtk.js render method?
2. Is it possible cache a processed image and pass that to the `render` method, removing the need to call `getRange`/`fastComputeRange`?

I am happy to work on a PR, but am not familiar with using `vtk.js` so any pointers on opportunities to how to optimise/improve the performance would be greatly appreciated. I can then work on a PR.

Cheers,

James
