steinwurf / recycle

Simple resource pool for recycling resources in C++
BSD 3-Clause "New" or "Revised" License
63 stars 23 forks source link

Sdmc 3146 #39

Closed daniel-swxtch closed 1 year ago

daniel-swxtch commented 1 year ago

Performance fix for SDMC-3146. For detailed information, please see the latest updates of: https://swxtchio.atlassian.net/browse/SDMC-3146

Summary: In old versions of the C++ Standard Library (4.x and older), the std::list::size() method has a linear complexity, i.e., O(N), meaning it takes more time as more elements are in the list (it iterates over all of its elements to count them). A prefill method in recycle was calling it in every iteration of a while-loop; the iterations then take longer as the list grows, causing the buffer prefill operation to take 5 minutes for a 131,072 entries prefill. The fix proposed in this PR calls list::size() only once, to know how many entries are required to be created and added to the list, and uses a simple counter to limit the filling loop.

daniel-swxtch commented 1 year ago

Closing this PR for now as I am investigating the reason some other commits leaked into this one.

daniel-swxtch commented 1 year ago

I now realize that I opened the PR to merge commits from our swxtch branch into steinwurf:master; this was unintended, I want to merge a change into our swxtch branch only. Sorry for the mistake.