Speed up integral images#79
Conversation
|
Beautiful! Have you benchmarked small images? 1024^2 or something? |
|
Good point @axtimwalde ! Our use case was large images (slices of compute blocks of large 3D stacks), so I focused on that. I rerun a small benchmark for
I haven't looked at the assembly instructions generated by the JIT compiler, but I suspect that all of this is 'just' more efficient memory access, since Java doesn't reliably compile SIMD instructions. Should this change in the future, the current way of doing column-wise summation is very amenable to this kind of automatic further optimizations. |
|
Thanks a lot! |
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