Skip to content

Optimize find_decision_points in agglomeration pipeline. - #124

Merged
copybara-service[bot] merged 1 commit into
masterfrom
test_947868587
Aug 14, 2026
Merged

Optimize find_decision_points in agglomeration pipeline.#124
copybara-service[bot] merged 1 commit into
masterfrom
test_947868587

Conversation

@copybara-service

@copybara-service copybara-service Bot commented Jul 14, 2026

Copy link
Copy Markdown

Optimize find_decision_points in agglomeration pipeline.

We optimized the decision point identification code to resolve slowness in the pipeline. The main bottlenecks were CPU-bound Python operations on large 3D arrays in a subvolume.

Bottlenecks and Fixes:

  • Vectorized Relabeling: Replaced the dict-based list comprehension in relabel (connectomics/segmentation/labels.py) with a vectorized implementation using np.searchsorted. This reduced the final relabeling time for a 12.5M voxel subvolume from ~16.7s to ~0.2s (78x speedup).
  • Slicing Optimization: Replaced ndimage.shift and np.roll with NumPy slicing views in the neighbor-checking loop (ffn/utils/decision_point.py), reducing loop time from ~2.1s to ~1.1s and avoiding memory copying.
  • DataFrame Aggregation: Collected NumPy arrays in lists and created a single DataFrame at the end of the loop, reducing pandas overhead.

Overall performance for find_decision_points on a representative dummy subvolume improved from 26.83s to 7.85s (3.4x speedup).

@copybara-service copybara-service Bot changed the title Optimize find_decision_points in neuromancer agglomeration pipeline. Optimize find_decision_points in agglomeration pipeline. Aug 14, 2026
@copybara-service
copybara-service Bot force-pushed the test_947868587 branch 3 times, most recently from ae1c089 to dacf8e4 Compare August 14, 2026 18:15
We optimized the decision point identification code to resolve slowness in the pipeline. The main bottlenecks were CPU-bound Python operations on large 3D arrays in a subvolume.

Bottlenecks and Fixes:
- **Vectorized Relabeling**: Replaced the dict-based list comprehension in `relabel` (connectomics/segmentation/labels.py) with a vectorized implementation using `np.searchsorted`. This reduced the final relabeling time for a 12.5M voxel subvolume from ~16.7s to ~0.2s (78x speedup).
- **Slicing Optimization**: Replaced `ndimage.shift` and `np.roll` with NumPy slicing views in the neighbor-checking loop (ffn/utils/decision_point.py), reducing loop time from ~2.1s to ~1.1s and avoiding memory copying.
- **DataFrame Aggregation**: Collected NumPy arrays in lists and created a single DataFrame at the end of the loop, reducing pandas overhead.

Overall performance for `find_decision_points` on a representative dummy subvolume improved from **26.83s to 7.85s (3.4x speedup)**.

PiperOrigin-RevId: 964798774
@copybara-service
copybara-service Bot merged commit c4e3e5c into master Aug 14, 2026
1 check failed
@copybara-service
copybara-service Bot deleted the test_947868587 branch August 14, 2026 18:26
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.

1 participant