ImagingDataCommons / dicomweb-client

Python client for DICOMweb RESTful services
https://dicomweb-client.readthedocs.io
MIT License
109 stars 38 forks source link

Use a generator to get bytes of `pydicom.Dataset`s #78

Closed pchristos closed 1 year ago

pchristos commented 1 year ago

in store_instances of DICOMwebClient.

The store_instances method accepts a set of DICOM frames, dumps them to bytes, and, finally, encodes them into a multipart/related request.

The above process results in storing the original DICOM frames in memory 3 times:

  1. as the original pydicom.Dataset instances passed into store_instances
  2. as bytes encoded in store_instances
  3. as the concatenation of the above bytes created in _encode_multipart_message

Using a generator in store_instances reduces memory footprint by 1/3, since the original pydicom.Datasets are dumped into bytes one by one while the multipart request body is being created by _encode_multipart_message.

hackermd commented 1 year ago

Thanks for your contribution @pchristos. Much appreciated. We will draft a new release and make a new version of the package available via pypi.