Speed up integral images #79
Merged
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.
While investigating a performance issue (which turned out to be unrelated to this library) in some downstream code, I found that some minimal changes could provide significant speedup: Integral images are accumulated row-wise and column-wise, where column-wise accumulation took significantly longer than the row-wise one.
This PR changes the memory access pattern of the column-wise accumulation to row-wise access, thereby significantly reducing the run time; see the changes in
IntIntegralImageas an example. These are the min/max run times for 10 runs of computing the integral image for a 20000x20000 image before and after the changes:All changes either change the accumulation in exactly the same manner, or are IDE warnings which are automatically fixed. For the former category of changes, I manually checked correctness by using images with elements
i -> 1andi -> i + 1.Let me know what you think, @axtimwalde