ENH: Segmentation Filters OoC Optimization#1559
Draft
joeykleingers wants to merge 8 commits intoBlueQuartzSoftware:developfrom
Draft
ENH: Segmentation Filters OoC Optimization#1559joeykleingers wants to merge 8 commits intoBlueQuartzSoftware:developfrom
joeykleingers wants to merge 8 commits intoBlueQuartzSoftware:developfrom
Conversation
48f1eea to
93b4565
Compare
Consolidate OOC filter optimizations from identify-sample-optimizations worktree: - Add AlgorithmDispatch.hpp and UnionFind.hpp utilities - SegmentFeatures: Add executeCCL() with 2-slice rolling buffer + Union-Find - ScalarSegmentFeatures: CCL dispatch + CompareFunctor::compare() - EBSDSegmentFeatures: CCL dispatch + isValidVoxel/areNeighborsSimilar - CAxisSegmentFeatures: CCL dispatch + isValidVoxel/areNeighborsSimilar - Tests: PreferencesSentinel, ForceOocAlgorithmGuard, 200^3 benchmarks
Update IdentifySample and FillBadData to use the AlgorithmDispatch BFS/CCL split pattern instead of monolithic inlined algorithms. Add BFS/CCL split files, update tests with ForceOocAlgorithmGuard, PreferencesSentinel, and 200x200x200 benchmark test cases.
Benchmark tests should let the dispatch happen naturally based on storage type, not force the OOC algorithm path. ForceOocAlgorithmGuard remains in correctness tests to exercise both code paths.
93b4565 to
935f5de
Compare
- Fix incorrect global index in IdentifySampleCommon hole-fill for XZ/YZ planes (was using flat local index instead of stride-based global index) - Move dp1/dp2 arrays to static constexpr class members in IdentifySampleSliceBySliceFunctor - Fix stale temp file reads in FillBadDataCCL phase 4 by tracking write position (rewind doesn't truncate) - Fix int32 truncation of uint64 region size in FillBadDataCCL phase 3 small-defect comparison - Propagate tmpfile() failure as Result<> error instead of silent message-only failure - Remove const from FillBadDataCCL::operator()() to match non-const member usage
… bugs - Fix k_ prefix on benchmark test constants (kDimX → k_DimX, etc.) in 5 test files - Add const to FillBadDataInputValues* across FillBadData/BFS/CCL headers and sources - Add ftell error check in FillBadDataCCL phase 4 - Replace // comment with /// @copydoc Doxygen on CCL virtual method overrides - Hoist GetAllChildDataPaths() out of iterative fill loop in FillBadDataBFS (pre-existing) - Fix float32 boundary checks to int64 in FillBadDataBFS iterative fill (pre-existing)
- ScalarSegmentFeatures.hpp: Replace // comment with proper /** */ blocks for isValidVoxel() and areNeighborsSimilar() overrides - IdentifySampleCommon.hpp: Add @class/@struct tags, add @brief/@param/@return to VectorUnionFind public methods and IdentifySampleSliceBySliceFunctor - SegmentFeatures.hpp: Fill in empty @param/@return descriptions on executeCCL()
0007b93 to
ca4ef6a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SegmentFeaturesbase class, replacing DFS flood-fill for OOC pathsUnionFind.hpputility class with path-halving compression and union-by-rankForceOocAlgorithmGuardcorrectness tests for all 5 filtersAlgorithm Decision
Problem
The original DFS flood-fill in
SegmentFeaturesuses random data access — each stack pop reads an arbitrary voxel then checks 6 scattered neighbors. For in-coreDataStorethis is fast, but forZarrStore-backed arrays every random access can trigger a chunk load/evict cycle, causing 50x–621x slowdowns.Solution: Chunk-Sequential CCL with Union-Find
A two-phase scanline algorithm that processes the grid in strict Z-Y-X order:
Phase 1 — Forward Labeling: Iterate every voxel in scanline order. For each valid voxel, check only backward neighbors (-X, -Y, -Z). Assign provisional labels and union equivalences in a Union-Find structure. A 2-slice rolling buffer (current + previous Z-slice) keeps all neighbor reads in RAM.
Phase 2 — Resolution and Relabeling: Flatten the Union-Find, then two sequential passes remap provisional labels to final feature IDs (assigned in seed-discovery order for compatibility with the original DFS numbering).
Why This Algorithm
executeCCL()inSegmentFeaturesserves all 4 subclasses viaisValidVoxel()andareNeighborsSimilar()virtual methodsDispatch
Each filter checks
IsOutOfCore(*featureIdsArray) || ForceOocAlgorithm():executeCCL()(chunk-sequential CCL)execute()(original DFS flood-fill)FillBadData (special case)
FillBadData uses its own 4-phase CCL (not the base class
executeCCL()):Split into
FillBadDataBFS.cpp(in-core) andFillBadDataCCL.cpp(OOC) with dispatch in the main algorithm class.Performance Results (200x200x200)
OOC baselines for 4 of 5 filters timed out at 1500s (DFS on ZarrStore). FillBadData's baseline already had CCL from PR #1515; this PR refactored it into separate BFS/CCL dispatch files.
Test plan
GENERATE(false, true)+ForceOocAlgorithmGuard)simplnx-Relandsimplnx-ooc-Relpresets