Skip to content

Conversation

Copy link

Copilot AI commented Nov 20, 2025

Selecting a volume triggers getAssociatedSegmentationFileNumber(), which calls pydicom.dcmread() once per SEG series in the study to check if it references the selected volume. With many SEG files, this causes ~30 second delays.

Changes

Added simple cache for referenced series lookups:

  • _referencedSeriesCache dict maps SEG series UID → referenced CT series UID
  • Modified getReferencedCtSeries() to check cache before reading DICOM files
  • Cache None for missing files/failures to avoid repeated errors
  • Added clearReferencedSeriesCache() for manual invalidation if needed

Result:

  • First call per SEG series: unchanged (reads DICOM)
  • Subsequent calls: O(1) dict lookup
  • Benefits getAssociatedSegmentationFileNumber() (line 773) and loadDicomSeries() (line 1826)
def getReferencedCtSeries(self, segmentation_uid):
    # Check cache first
    if segmentation_uid in self._referencedSeriesCache:
        return self._referencedSeriesCache[segmentation_uid]
    
    # Read DICOM file only if not cached
    ds = pydicom.dcmread(series_files[0], stop_before_pixels=True, specific_tags=["ReferencedSeriesSequence"])
    referenced_series = ds.ReferencedSeriesSequence[0].SeriesInstanceUID
    self._referencedSeriesCache[segmentation_uid] = referenced_series
    return referenced_series

Cache is safe since DICOM Series Instance UIDs are immutable identifiers.

Original prompt

This section details on the original issue you should resolve

<issue_title>Long delay/reaction time after selecting input volume</issue_title>
<issue_description></issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits November 20, 2025 16:00
Co-authored-by: fedorov <313942+fedorov@users.noreply.github.com>
Co-authored-by: fedorov <313942+fedorov@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix long delay after selecting input volume Cache DICOM SEG referenced series UIDs to eliminate 30s delay on volume selection Nov 20, 2025
Copilot AI requested a review from fedorov November 20, 2025 16:08
Copilot finished work on behalf of fedorov November 20, 2025 16:08
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.

Long delay/reaction time after selecting input volume

3 participants