Skip to content

Comments

PERF: Make IndexRange iterators _much_ faster, by m_Position data member#5808

Merged
hjmjohnson merged 1 commit intoInsightSoftwareConsortium:mainfrom
N-Dekker:IndexRange-m_Position
Feb 17, 2026
Merged

PERF: Make IndexRange iterators _much_ faster, by m_Position data member#5808
hjmjohnson merged 1 commit intoInsightSoftwareConsortium:mainfrom
N-Dekker:IndexRange-m_Position

Conversation

@N-Dekker
Copy link
Contributor

Added a numeric data member to the iterator types of IndexRange, denoting the position of an iterator relative to the begin of its IndexRange. Used to speed up its comparison operators.

The following code became more than 4x as fast, using Visual Studio 2026 (Release build). For a region size of around 100'000 x 10'000, the duration went from ~1.9 sec (before this commit) down to ~0.4 sec (after this commit).

for (const auto & index: ImageRegionIndexRange<2>(region))
{
  result += index[0] - index[1];
}

Added a numeric data member to the iterator types of IndexRange, denoting the
position of an iterator relative to the begin of its IndexRange. Used to speed
up its comparison operators.

The following code became more than 4x as fast, using Visual Studio 2026
(Release build). For a region size of around 100'000 x 10'000, the duration went
from ~1.9 sec (before this commit) down to ~0.4 sec (after this commit).

    for (const auto & index: ImageRegionIndexRange<2>(region))
    {
      result += index[0] - index[1];
    }
@github-actions github-actions bot added type:Performance Improvement in terms of compilation or execution time area:Core Issues affecting the Core module labels Feb 17, 2026
@N-Dekker N-Dekker marked this pull request as ready for review February 17, 2026 11:56
@hjmjohnson hjmjohnson merged commit 02d38fd into InsightSoftwareConsortium:main Feb 17, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Core Issues affecting the Core module type:Performance Improvement in terms of compilation or execution time

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants