Boost C++ Libraries: Ticket #3789: boost::object_pool::free() is very slow. https://svn.boost.org/trac10/ticket/3789 <blockquote> <p> boost::object_pool::free() Design is very bad。The main problem is in : [void * simple_segregated_storage&lt;<a class="missing wiki">SizeType</a>&gt;::find_prev(void * const ptr)] Whenever a user to delete a node, we must traverse to the previous nodes from list head. Means, if we have created 10,000 objects and 9,000 removed from the ground, then when the user to delete the first 9001 objects, he would traverse the list from scratch 9,000 times. </p> </blockquote> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3789 Trac 1.4.3 Dai Yun <dy95020@…> Tue, 22 Dec 2009 07:05:12 GMT attachment set https://svn.boost.org/trac10/ticket/3789 https://svn.boost.org/trac10/ticket/3789 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">object_pool.rar</span> </li> </ul> <p> object_pool.hpp + Main.hpp </p> Ticket John Maddock Fri, 07 Jan 2011 11:23:57 GMT cc set https://svn.boost.org/trac10/ticket/3789#comment:1 https://svn.boost.org/trac10/ticket/3789#comment:1 <ul> <li><strong>cc</strong> <span class="trac-author">boostpool@…</span> added </li> </ul> Ticket anonymous Mon, 17 Oct 2011 07:22:36 GMT <link>https://svn.boost.org/trac10/ticket/3789#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3789#comment:2</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/3789#comment:1" title="Comment 1">johnmaddock</a>: Why is this patch not getting applied in all the boost releases till now? Any specific reason.. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 17 Oct 2011 11:56:49 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3789#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3789#comment:3</guid> <description> <p> There are so many differences between your version and current trunk, that I can't figure out what you're proposing: can you please post a diff and/or explain what changes you're proposing? </p> <p> BTW, there is no maintainer for Boost.Pool at present which is why this issue has languished for so long :-( I will try and figure out how to fix this issue though... </p> <p> John Maddock. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 31 Oct 2011 08:35:08 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3789#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3789#comment:4</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/3789#comment:3" title="Comment 3">anonymous</a>: </p> <blockquote class="citation"> <p> There are so many differences between your version and current trunk, that I can't figure out what you're proposing: can you please post a diff and/or explain what changes you're proposing? </p> </blockquote> <p> The version submitted here is not mine, but i wrote the comment2. I was just interested to know, when there will be a fix. </p> <p> Thanks, Gokul. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>edupuis</dc:creator> <pubDate>Thu, 03 May 2012 16:46:18 GMT</pubDate> <title>owner, status changed https://svn.boost.org/trac10/ticket/3789#comment:5 https://svn.boost.org/trac10/ticket/3789#comment:5 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Peng Yu</span> to <span class="trac-author">edupuis</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket edupuis Thu, 03 May 2012 19:54:40 GMT <link>https://svn.boost.org/trac10/ticket/3789#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3789#comment:6</guid> <description> <p> Patch is a complete rewrite of object_pool. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>edupuis</dc:creator> <pubDate>Fri, 04 May 2012 05:27:01 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3789#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3789#comment:7</guid> <description> <p> In fact the current implementation is as follows : </p> <ul><li>O(1) for requesting an object, thus O(n) to request n objects; </li><li>O(n) for releasing an object, thus O(n<sup>2</sup>) to release n objects; </li><li>O(n) for deleting the pool. </li></ul><p> In my opinion, it would be better if it was </p> <ul><li>O(1) for requesting an object, thus O(n) to request n objects; </li><li>O(1) for releasing an object, thus O(n) to release n objects; </li><li>O(n<sup>2</sup>) for deleting the pool or O(1) if the user kindly released all requested objects. Using a sort algorithm, it is perhaps possible to make this O(n log n). </li></ul> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Sat, 05 May 2012 08:55:12 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3789#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3789#comment:8</guid> <description> <p> I'm not sure that what you're looking for is actually possible? </p> <p> The problem here is that object_pool always calls the ordered_(allocate|free) functions which are slow to free when there are a lot of free objects in the underlying pool. </p> <p> IMO it would have been better to have had object_pool have two allocate/free functions (ordered and unordered) like pool does, I thought about making that change, but it's a breaking change so I resisted it. Better still I can't help but thinking that the whole design is wrong (having ordered and unordered free methods in the same class that is). Then if you get into O(N) ordered free you're basically reimplementing the system allocator which is the whole thing that pool was trying to avoid. Maybe this limitation should just have better documentation - that pool is designed for fast allocate/free of small numbers of objects - and is not a complete heap replacement? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>edupuis</dc:creator> <pubDate>Tue, 08 May 2012 10:42:37 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3789#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3789#comment:9</guid> <description> <p> Hi John, </p> <p> The change I am proposing is possible (see ticket <a class="new ticket" href="https://svn.boost.org/trac10/ticket/6610" title="#6610: Feature Requests: customizing boost::pool/boost::object_pool via template parameter for ... (new)">#6610</a>); I would simply modify object_pool call the non ordered version of malloc and free. I would need also a member function 'order' who whould order the pool, function that could be called in the destructor prior to applying the method that destroys all non released object. </p> <p> The pool.order() method would be O(n log n) complexity, using an in-place merge sort. </p> <p> This modification I am suggesting would not break the API, only speed-up the free function and slow down the destructor, for those lazy programmers that do not release all objects they have allocated... </p> <p> Now that I have started digging into the code (I have already fixed tickets <a class="new ticket" href="https://svn.boost.org/trac10/ticket/5902" title="#5902: Bugs: Division by zero when requesting null sized buffers (new)">#5902</a>, <a class="new ticket" href="https://svn.boost.org/trac10/ticket/6561" title="#6561: Bugs: pool.free() crashes if given a null pointer (new)">#6561</a>, <a class="new ticket" href="https://svn.boost.org/trac10/ticket/6701" title="#6701: Bugs: integer overflows in ordered_malloc() (new)">#6701</a>, <a class="new ticket" href="https://svn.boost.org/trac10/ticket/6865" title="#6865: Feature Requests: pool.get_size() (new)">#6865</a> and <a class="new ticket" href="https://svn.boost.org/trac10/ticket/6867" title="#6867: Bugs: Unclear behavior of parameter 'max_size' (new)">#6867</a> in the boost sandbox), I agree with you that the design is weird and could be improved a lot. </p> <p> For example, the fact that the user supplied allocator is made of static non member functions makes it almost impossible to make something useful of it. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>edupuis</dc:creator> <pubDate>Tue, 08 May 2012 10:43:02 GMT</pubDate> <title>cc changed https://svn.boost.org/trac10/ticket/3789#comment:10 https://svn.boost.org/trac10/ticket/3789#comment:10 <ul> <li><strong>cc</strong> <span class="trac-author">edupuis</span> added </li> </ul> Ticket edupuis Thu, 10 May 2012 21:10:58 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/3789#comment:11 https://svn.boost.org/trac10/ticket/3789#comment:11 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/78412" title="Added a pool.order() function, which transforms an unordered pool into ...">[78412]</a>) Added a pool.order() function, which transforms an unordered pool into an ordered one. Call this function in object_pool::~object_pool() if suitable, which allows to use pool.malloc() and pool.free() instead of pool.ordered_malloc() and pool.ordered_free(). </p> <p> This changes the complexity of object_pool.destroy(), going from O(n) to O(1), while the complexity of the destructor goes from O(n) to O(n log n) if the pool user has not released all pool objects, otherwise the destructor is O(1). </p> <p> This fixes <a class="new ticket" href="https://svn.boost.org/trac10/ticket/3789" title="#3789: Bugs: boost::object_pool::free() is very slow. (new)">#3789</a> and makes it possible to have pools holding millions of objects. </p> Ticket edupuis Mon, 21 May 2012 05:59:09 GMT status changed; resolution deleted https://svn.boost.org/trac10/ticket/3789#comment:12 https://svn.boost.org/trac10/ticket/3789#comment:12 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> </ul> Ticket anonymous Tue, 22 May 2012 06:42:43 GMT milestone changed https://svn.boost.org/trac10/ticket/3789#comment:13 https://svn.boost.org/trac10/ticket/3789#comment:13 <ul> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.42.0</span> → <span class="trac-field-new">To Be Determined</span> </li> </ul> Ticket edupuis Mon, 16 Jul 2012 19:59:27 GMT cc, owner, status changed https://svn.boost.org/trac10/ticket/3789#comment:14 https://svn.boost.org/trac10/ticket/3789#comment:14 <ul> <li><strong>cc</strong> <span class="trac-author">edupuis</span> removed </li> <li><strong>owner</strong> changed from <span class="trac-author">edupuis</span> to <span class="trac-author">John Maddock</span> </li> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">new</span> </li> </ul> <p> <a class="ext-link" href="https://svn.boost.org/svn/boost/sandbox/pool"><span class="icon">​</span>https://svn.boost.org/svn/boost/sandbox/pool</a> at revision 79460 contains a solution for tickets <a class="new ticket" href="https://svn.boost.org/trac10/ticket/3789" title="#3789: Bugs: boost::object_pool::free() is very slow. (new)">#3789</a>, <a class="new ticket" href="https://svn.boost.org/trac10/ticket/5902" title="#5902: Bugs: Division by zero when requesting null sized buffers (new)">#5902</a>, <a class="new ticket" href="https://svn.boost.org/trac10/ticket/6561" title="#6561: Bugs: pool.free() crashes if given a null pointer (new)">#6561</a>, <a class="new ticket" href="https://svn.boost.org/trac10/ticket/6610" title="#6610: Feature Requests: customizing boost::pool/boost::object_pool via template parameter for ... (new)">#6610</a>, <a class="new ticket" href="https://svn.boost.org/trac10/ticket/6701" title="#6701: Bugs: integer overflows in ordered_malloc() (new)">#6701</a>, <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6718" title="#6718: Bugs: Missing images (closed: fixed)">#6718</a>, <a class="new ticket" href="https://svn.boost.org/trac10/ticket/6865" title="#6865: Feature Requests: pool.get_size() (new)">#6865</a> and <a class="new ticket" href="https://svn.boost.org/trac10/ticket/6867" title="#6867: Bugs: Unclear behavior of parameter 'max_size' (new)">#6867</a>. Related test cases are also present. </p> <p> <a class="ext-link" href="https://svn.boost.org/svn/boost/sandbox/pool"><span class="icon">​</span>https://svn.boost.org/svn/boost/sandbox/pool</a> at revision 79460 does <strong>not</strong> contain any other new features or modifications other than those related to the above tickets. </p> <p> Boost.Pool currently has no maintainer and is thus orphaned. </p> Ticket anonymous Fri, 07 Jun 2013 23:03:13 GMT <link>https://svn.boost.org/trac10/ticket/3789#comment:15 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3789#comment:15</guid> <description> <p> I was recently hit by this problem. In my application, if I use boost::object_pool, it runs 12 seconds. Through profiling, I know it was due to find_prev(). So I replaced it with boost:pool. Now it finishes in 1 second. </p> <p> I was wondering if we can simply do the following change to fix the problem? </p> <blockquote> <p> void free BOOST_PREVENT_MACRO_SUBSTITUTION(element_type * const chunk) { <em>... </em></p> <blockquote> <p> store().ordered_free(chunk); </p> </blockquote> <p> } </p> </blockquote> <p> to </p> <blockquote> <p> void free BOOST_PREVENT_MACRO_SUBSTITUTION(element_type * const chunk) { <em>... </em></p> <blockquote> <p> store().free(chunk); </p> </blockquote> <p> } </p> </blockquote> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Sat, 07 May 2016 00:14:46 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3789#comment:16 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3789#comment:16</guid> <description> <p> I think there is a much better solution than those previously proposed. </p> <p> The object pool currently contains a single linked list of free objects, which makes it o(1) to allocate a single object. Why not simply to have two linked lists -- one for freed objects and one for allocated objects? Then freeing all allocated objects becomes O(N) and freeing N objects manually is also O(N). </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Sat, 07 May 2016 00:14:48 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3789#comment:16 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3789#comment:16</guid> <description> <p> I think there is a much better solution than those previously proposed. </p> <p> The object pool currently contains a single linked list of free objects, which makes it o(1) to allocate a single object. Why not simply to have two linked lists -- one for freed objects and one for allocated objects? Then freeing all allocated objects becomes O(N) and freeing N objects manually is also O(N). </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Sat, 07 May 2016 00:14:49 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3789#comment:16 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3789#comment:16</guid> <description> <p> I think there is a much better solution than those previously proposed. </p> <p> The object pool currently contains a single linked list of free objects, which makes it o(1) to allocate a single object. Why not simply to have two linked lists -- one for freed objects and one for allocated objects? Then freeing all allocated objects becomes O(N) and freeing N objects manually is also O(N). </p> </description> <category>Ticket</category> </item> <item> <author>feicheng@…</author> <pubDate>Fri, 29 Jul 2016 05:17:08 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3789#comment:17 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3789#comment:17</guid> <description> <p> Boost.Pool currently has no maintainer and is thus orphaned. </p> <p> so bad................. </p> </description> <category>Ticket</category> </item> </channel> </rss>