Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Remove redundant array copy for TiffFileWSIReader#6089

Merged
bhashemian merged 2 commits into
Project-MONAI:devfrom
bhashemian:fix-5580-wsireader-tifffile-performance
Mar 2, 2023
Merged

Remove redundant array copy for TiffFileWSIReader#6089
bhashemian merged 2 commits into
Project-MONAI:devfrom
bhashemian:fix-5580-wsireader-tifffile-performance

Conversation

@bhashemian

@bhashemian bhashemian commented Mar 1, 2023

Copy link
Copy Markdown
Member

Fixes #5580

Description

This PR removes an "unnecessary" array copy in WSITiffFileReader, which was causing an slow down in loading whole slide images.

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).

@bhashemian bhashemian requested review from Nic-Ma and wyli March 1, 2023 21:42
@bhashemian bhashemian enabled auto-merge (squash) March 1, 2023 21:43
@bhashemian bhashemian changed the title Remove redundant array copy for WSITiffFileReader Remove redundant array copy for TiffFileWSIReader Mar 1, 2023
@bhashemian

Copy link
Copy Markdown
Member Author
from monai.data.wsi_reader import WSIReader
from monai.data.image_reader import WSIReader as WSIReader2

filename = "temp_CMU-1.tiff"
reader1 = WSIReader(backend="TiffFile")
reader2 = WSIReader2(backend="TiffFile")
obj1 = reader1.read(filename)
obj2 = reader2.read(filename)
%%timeit
reader1.get_data(obj1, level=1)

current performance: 2.32 s ± 97.7
after fixing the issue: 1.45 s ± 12.9 ms

%%timeit
reader2.get_data(obj2, level=1)

current performance: 1.97 s ± 50.2 ms
after fixing the issue:. 1.93 s ± 141 ms

@wyli

wyli commented Mar 1, 2023

Copy link
Copy Markdown
Contributor

thanks, is it possible to add a test to avoid regression?

@wyli

wyli commented Mar 1, 2023

Copy link
Copy Markdown
Contributor

/build

@bhashemian

Copy link
Copy Markdown
Member Author

thanks, is it possible to add a test to avoid regression?

Since it was a performance regression, I am not sure how we should set the criteria for the test as it is hardware dependent, especially when dealing with variability across different run of the same class. Do you have any suggestion? Maybe we should just check for regression whenever we have a major change.

@wyli

wyli commented Mar 1, 2023

Copy link
Copy Markdown
Contributor

Maybe just check theres no array copy, which means changing the patch would also change the input array?

@bhashemian

Copy link
Copy Markdown
Member Author

Maybe just check theres no array copy, which means changing the patch would also change the input array?

Right but in this case there is mo use for the input array since the array input is loaded from disk and is being prepared based on the arguments, so if we copy the original array, it will be discarded anyway.

@wyli

wyli commented Mar 2, 2023

Copy link
Copy Markdown
Contributor

Sure, there was a similar performance bug earlier #3322 hope we can add some tests to avoid reoccurring

@wyli wyli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be great to have some integration tests

@wyli

wyli commented Mar 2, 2023

Copy link
Copy Markdown
Contributor

/build

@wyli

wyli commented Mar 2, 2023

Copy link
Copy Markdown
Contributor

/build

@bhashemian bhashemian merged commit 934ba09 into Project-MONAI:dev Mar 2, 2023
@bhashemian bhashemian deleted the fix-5580-wsireader-tifffile-performance branch March 2, 2023 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WSIReader, cucim , tifffile, performance regressions

2 participants