Improves FLANN's heap allocations by a memory pool#20460
Improves FLANN's heap allocations by a memory pool#20460opencv-pushbot merged 1 commit intoopencv:masterfrom
Conversation
b479984 to
2ac046c
Compare
|
Hi @alalek, I believe this PR is ready for your review. |
alalek
left a comment
There was a problem hiding this comment.
Thank you for the contribution!
Please take a look on the comments below.
modules/flann/include/opencv2/flann/hierarchical_clustering_index.h
Outdated
Show resolved
Hide resolved
|
@alalek I revised according to your valuable comments. Please let me know if you still think there are some remaining improvements that can be made. |
|
@alalek Appreciate your followup. |
|
Please take a look on warnings from 32-bit compilation on Linux platforms. |
|
@alalek Now |
alalek
left a comment
There was a problem hiding this comment.
Looks good to me! Thank you for contribution 👍
FLANN allocates huge amounts of memory with every call to
findNeighborsdue to its private heap allocations. This affects memory throughput and overall speed of user applications, especially the ones that frequently query for neighbors. After all, althoughmallocdoes cache on its own, it also does a lot of smart things besides that, which costs some time penalty. To solve the problem, this PR introduces a static, thread-safe, and bounded memory pool for heap allocations. It have been tested thoroughly for very long hours, under extensive parallelization, and with strict leakage profiling. The tests showed more than 70x memory throughput gain. For roughly the same amount of calls, the memory footprint offindNeighborsusing master branch was around 18.2 GB/sec, which got reduced by this PR to just 250.5 MB/sec (see the allocations throughput table below). Additionally, this PR cleans up some unnecessary variables in thecvflann::Heapclass.Pull Request Readiness Checklist
Already existing:
Patch to opencv_extra has the same branch name.