Boost C++ Libraries: Ticket #4780: Many deadline_timer objects triggers worst-case vector reallocation in timer_queue https://svn.boost.org/trac10/ticket/4780 <p> Using the g++ 4.4.5 on linux x86_64, the following program: </p> <pre class="wiki">#include &lt;boost/asio/deadline_timer.hpp&gt; boost::asio::io_service io_service; struct timer { boost::asio::deadline_timer t; timer() : t(io_service) {} } timers[100000]; void handler(boost::system::error_code) {} int main() { for (std::size_t i = 0; i &lt; 100000; ++i) { timers[i].t.expires_from_now(boost::posix_time::seconds(1000)); timers[i].t.async_wait(handler); } } </pre><p> takes a very long time to run: </p> <pre class="wiki">$ time ./a.out real 0m48.504s user 0m21.469s sys 0m27.038s </pre><p> This is due to the vector&lt;&gt;-based heap in asio::detail::timer_queue reserve()-ing one element at a time. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4780 Trac 1.4.3 chris_kohlhoff Sun, 24 Oct 2010 02:07:16 GMT <link>https://svn.boost.org/trac10/ticket/4780#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4780#comment:1</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/66158" title="Fix vector reallocation performance problem. Refs #4780. ">[66158]</a>) Fix vector reallocation performance problem. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4780" title="#4780: Bugs: Many deadline_timer objects triggers worst-case vector reallocation in ... (closed: fixed)">#4780</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>chris_kohlhoff</dc:creator> <pubDate>Sun, 24 Oct 2010 02:09:37 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4780#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4780#comment:2</guid> <description> <p> Performance of test program after fix: </p> <pre class="wiki">$ time ./a.out real 0m0.096s user 0m0.084s sys 0m0.012s </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>chris_kohlhoff</dc:creator> <pubDate>Mon, 25 Oct 2010 10:44:41 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/4780#comment:3 https://svn.boost.org/trac10/ticket/4780#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</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/66173" title="Merge from trunk. ........ r66075 | chris_kohlhoff | 2010-10-18 ...">[66173]</a>) Merge from trunk. ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/66075" title="Fix unused parameter warnings. ">r66075</a> | chris_kohlhoff | 2010-10-18 23:27:12 +1100 (Mon, 18 Oct 2010) | 2 lines </p> </blockquote> <p> </p> <blockquote> <p> Fix unused parameter warnings. </p> </blockquote> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/66143" title="Redefine Protocol and id to avoid clashing with Objective-C++ ...">r66143</a> | chris_kohlhoff | 2010-10-22 23:07:36 +1100 (Fri, 22 Oct 2010) | 2 lines </p> </blockquote> <p> </p> <blockquote> <p> Redefine Protocol and id to avoid clashing with Objective-C++ keywords. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4191" title="#4191: Patches: c++ library using regex included in objective-c needs rename of variable id (closed: fixed)">#4191</a>. </p> </blockquote> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/66144" title="Version check not required. ">r66144</a> | chris_kohlhoff | 2010-10-22 23:20:52 +1100 (Fri, 22 Oct 2010) | 2 lines </p> </blockquote> <p> </p> <blockquote> <p> Version check not required. </p> </blockquote> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/66156" title="Fix for IBM C++ compiler. ">r66156</a> | chris_kohlhoff | 2010-10-24 11:26:10 +1100 (Sun, 24 Oct 2010) | 2 lines </p> </blockquote> <p> </p> <blockquote> <p> Fix for IBM C++ compiler. </p> </blockquote> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/66158" title="Fix vector reallocation performance problem. Refs #4780. ">r66158</a> | chris_kohlhoff | 2010-10-24 13:06:46 +1100 (Sun, 24 Oct 2010) | 2 lines </p> </blockquote> <p> </p> <blockquote> <p> Fix vector reallocation performance problem. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4780" title="#4780: Bugs: Many deadline_timer objects triggers worst-case vector reallocation in ... (closed: fixed)">#4780</a>. </p> </blockquote> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/66159" title="Fix kqueue_reactor so that it compiles on NetBSD. Refs #4662. ">r66159</a> | chris_kohlhoff | 2010-10-24 18:58:23 +1100 (Sun, 24 Oct 2010) | 2 lines </p> </blockquote> <p> </p> <blockquote> <p> Fix kqueue_reactor so that it compiles on NetBSD. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4662" title="#4662: Bugs: asio is not usable on NetBSD (using kqueue) (closed: fixed)">#4662</a>. </p> </blockquote> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/66162" title="Fix failure in socket_base test on NetBSD. ">r66162</a> | chris_kohlhoff | 2010-10-25 00:15:46 +1100 (Mon, 25 Oct 2010) | 2 lines </p> </blockquote> <p> </p> <blockquote> <p> Fix failure in socket_base test on NetBSD. </p> </blockquote> <p> ........ </p> Ticket