Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce allocations during readNativeFrames (#157)
This change reduces the number of allocations in `readNativeFrames`. Instead of allocating a slice for each pixel's samples, a single flat buffer slice is allocated upfront of the size `pixelsPerFrame*samplesPerPixel`. Later, ranges in that slice are referred to in the larger 2D slice. This leads to there only being two calls to `make`, leading to significant performance gains. On my machine running `make bench-diff`: ``` name old time/op new time/op delta Parse/1.dcm-8 2.29ms ± 1% 1.95ms ± 3% -15.00% (p=0.008 n=5+5) Parse/2.dcm-8 2.27ms ± 1% 1.94ms ± 0% -14.41% (p=0.008 n=5+5) Parse/3.dcm-8 2.10ms ± 0% 1.81ms ± 2% -13.77% (p=0.008 n=5+5) Parse/4.dcm-8 240ms ± 1% 196ms ± 4% -18.27% (p=0.008 n=5+5) Parse/5.dcm-8 33.6ms ± 1% 27.9ms ± 0% -17.00% (p=0.008 n=5+5) ``` We see similar results in the [GitHub action benchmark](https://github.com/suyashkumar/dicom/pull/157/checks?check_run_id=1574909456#step:5:26). Presumably the percentage performance gains would be even higher for DICOMs with more Native PixelData (e.g. more frames, pixels per frame, samples per pixel, etc). This helps address #161.
- Loading branch information