cornerstoneWADOImageLoader icon indicating copy to clipboard operation
cornerstoneWADOImageLoader copied to clipboard

fix: copy buffer to prevent oom in workers

Open Ouwen opened this issue 3 years ago • 3 comments
trafficstars

Large uncompressed multiframe data will send the full arraybuffer in a typed view. For large uncompressed data such as tomo these will result in OOM issues. This fix pre-slices the typed array view so only used buffer is sent via worker.postMessage.

Ouwen avatar Jun 28 '22 16:06 Ouwen

Deploy Preview for cornerstone-wado-image-loader ready!

Name Link
Latest commit f793009171f33f7cdd73ce2840d9011ffd9173aa
Latest deploy log https://app.netlify.com/sites/cornerstone-wado-image-loader/deploys/62bb2e76b7e57e000a4f031b
Deploy Preview https://deploy-preview-454--cornerstone-wado-image-loader.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

netlify[bot] avatar Jun 28 '22 16:06 netlify[bot]

The preview is not loading for me:

Uncaught (in promise) DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'blob:https://deploy-preview-454--cornerstone-wado-image-loader.netlify.app/888.bundle.min.worker.js' failed to load.
    at B.f.i (blob:https://deploy-preview-454--cornerstone-wado-image-loader.netlify.app/cc21dc5d-801e-4e29-8d21-aeb5b116536c:1:795575)
    at blob:https://deploy-preview-454--cornerstone-wado-image-loader.netlify.app/cc21dc5d-801e-4e29-8d21-aeb5b116536c:1:794747
    at Array.reduce (<anonymous>)
    at B.e (blob:https://deploy-preview-454--cornerstone-wado-image-loader.netlify.app/cc21dc5d-801e-4e29-8d21-aeb5b116536c:1:794725)
    at blob:https://deploy-preview-454--cornerstone-wado-image-loader.netlify.app/cc21dc5d-801e-4e29-8d21-aeb5b116536c:1:807294
    at new Promise (<anonymous>)
    at new I (blob:https://deploy-preview-454--cornerstone-wado-image-loader.netlify.app/cc21dc5d-801e-4e29-8d21-aeb5b116536c:1:120704)
    at yA (blob:https://deploy-preview-454--cornerstone-wado-image-loader.netlify.app/cc21dc5d-801e-4e29-8d21-aeb5b116536c:1:807268)
    at blob:https://deploy-preview-454--cornerstone-wado-image-loader.netlify.app/cc21dc5d-801e-4e29-8d21-aeb5b116536c:1:807529
    at a (blob:https://deploy-preview-454--cornerstone-wado-image-loader.netlify.app/cc21dc5d-801e-4e29-8d21-aeb5b116536c:1:1528)

dereklukacs avatar Jul 12 '22 20:07 dereklukacs

How can I use this solution to handle out of memory Problem ?

muhammedmokbel avatar Aug 09 '22 09:08 muhammedmokbel

Thanks @Ouwen! This solves a big problem and we definitely want it merged.

Some feedback before we can merge this, though:

  • Add a check if SharedArrayBuffer exists and if the window.crossOriginIsolated is true. If those are true, use a SharedArrayBuffer for the pixel data for WADO-URI. Then it doesn’t need to be transferred to the worker at all. We can run the check once on library initialization.
  • If the check is false, use .slice() to copy the buffer. That means this function getUncompressedImageFrame should have a third argument for “copyPixelData” or some other name (default false) which should enable the usage of .slice(). For WADO-RS we do not want this behaviour. We only want it when SharedArrayBuffer is not supported AND it is WADO-URI or a local DICOM file.

Tagging @jmannau because he's asked about this in Slack.

swederik avatar Dec 14 '22 09:12 swederik

The fix works great for me in the given example with a 293 slice US

jpotwarka avatar Jan 13 '23 14:01 jpotwarka

Hello, this is a great PR as it solves our problem. Any chance of it to be finished and merged? Thank you!

justvamp avatar Mar 02 '23 11:03 justvamp

Hi all, It looks like this fix may solve our memory crash problem in Windows machines. Any chance of merging it soon? Thank you!

OzgeYurtsever avatar Apr 24 '23 16:04 OzgeYurtsever

:tada: This PR is included in version 4.13.2 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

sedghi avatar Jun 14 '23 03:06 sedghi