<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 02:56:34 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[SERVER-1272] mongo::BufBuilder::grow fails to be inlined, makes appending slow</title>
                <link>https://jira.mongodb.org/browse/SERVER-1272</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;When profiling a program making heavy use of the BSON library, I noticed that a large percentage of time was spent in mongo::BufBuilder::grow. That was odd since I had pre-configured BufBuilder objects with a generous chunk of memory, and I confirmed that realloc was not being called, so the buffer was never actually growing.&lt;/p&gt;

&lt;p&gt;It turns out that the compiler was not inlining mongo::BufBuilder::grow. The function was emitted out-of-line and was being called through the PLT to do so much as append an integer to an already allocated buffer.&lt;/p&gt;

&lt;p&gt;I was able to improve throughput a good bit by partitioning BufBuilder::grow into a hot inlined function do to the space check, and an explicitly non-inlined cold function to handle reallocating on overflow:&lt;/p&gt;

&lt;p&gt;        /* returns the pre-grow write position */&lt;br/&gt;
        inline char* grow(int by) {&lt;br/&gt;
            int oldlen = l;&lt;br/&gt;
            l += by;&lt;br/&gt;
            if ( l &amp;gt; size ) &lt;/p&gt;
{
                grow_reallocate();
            }
&lt;p&gt;            return data + oldlen;&lt;br/&gt;
        }&lt;/p&gt;

&lt;p&gt;        void grow_reallocate() _&lt;em&gt;attribute&lt;/em&gt;_((noinline))&lt;/p&gt;
        {
            int a = size * 2;
            if ( a == 0 )
                a = 512;
            if ( l &amp;gt; a )
                a = l + 16 * 1024;
            if( a &amp;gt; 64 * 1024 * 1024 )
                msgasserted(10000, &quot;BufBuilder grow() &amp;gt; 64MB&quot;);
            data = (char *) realloc(data, a);
            size= a;
        }

&lt;p&gt;After this change, the available space check was inlined during BufBuilder::append calls, and grow_reallocate was emitted out of line (and never called) This seemed to buy me about a 20% improvement in throughput while constructing complex BSON documents.&lt;/p&gt;

&lt;p&gt;The _&lt;em&gt;attribute&lt;/em&gt;&lt;em&gt;((noinline)) is necessary here, since I don&apos;t want grow_reallocate inlined into &apos;grow&apos;. Ideally, grow_reallocate would be at .cc scope, not in the header at all, but perhaps you want to keep the BSON library &apos;header only&apos;. If that is the case, then maybe think about macroizing __attribute&lt;/em&gt;_((noinline)), and then marking cold functions, or functions that make expensive library calls like &apos;realloc&apos;, as non-inline-able, as there is little or no benefit to inlining them. Similarly, splitting in-header functions that may be complicated enough that the compiler could reasonably choose not to inline into an inlined hot/fast-path and a non-inlined slow/cold-path could allow the compiler to more aggressively inline common cases.&lt;/p&gt;</description>
                <environment>Ubuntu 10.04 x86_64, gcc-4.4.3</environment>
        <key id="12212">SERVER-1272</key>
            <summary>mongo::BufBuilder::grow fails to be inlined, makes appending slow</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="9">Done</resolution>
                                        <assignee username="alerner">Alberto Lerner</assignee>
                                    <reporter username="andrew.morrow@mongodb.com">Andrew Morrow</reporter>
                        <labels>
                    </labels>
                <created>Mon, 21 Jun 2010 12:49:30 +0000</created>
                <updated>Tue, 12 Jul 2016 00:29:15 +0000</updated>
                            <resolved>Tue, 20 Jul 2010 19:40:49 +0000</resolved>
                                    <version>1.5.3</version>
                                    <fixVersion>1.5.6</fixVersion>
                                    <component>Internal Client</component>
                                        <votes>0</votes>
                                    <watches>0</watches>
                                                                                                                <comments>
                            <comment id="15985" author="auto" created="Tue, 20 Jul 2010 17:46:02 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;login&apos;: &apos;alerner&apos;, &apos;name&apos;: &apos;Alberto Lerner&apos;, &apos;email&apos;: &apos;alerner@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-1272&quot; title=&quot;mongo::BufBuilder::grow fails to be inlined, makes appending slow&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-1272&quot;&gt;&lt;del&gt;SERVER-1272&lt;/del&gt;&lt;/a&gt; Inline hot portion of BufBuild::grow()&lt;br/&gt;
&lt;a href=&quot;http://github.com/mongodb/mongo/commit/9c33f219fb8bdc414089dff8c4dcbc8d65d0ee8f&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://github.com/mongodb/mongo/commit/9c33f219fb8bdc414089dff8c4dcbc8d65d0ee8f&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="15471" author="auto" created="Tue, 6 Jul 2010 21:13:23 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;login&apos;: &apos;alerner&apos;, &apos;name&apos;: &apos;Alberto Lerner&apos;, &apos;email&apos;: &apos;alerner@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-1272&quot; title=&quot;mongo::BufBuilder::grow fails to be inlined, makes appending slow&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-1272&quot;&gt;&lt;del&gt;SERVER-1272&lt;/del&gt;&lt;/a&gt; Separate slow portion of hot function&lt;br/&gt;
&lt;a href=&quot;http://github.com/mongodb/mongo/commit/62a6e478d619c6ce27cadec5d533ea207d9e0790&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://github.com/mongodb/mongo/commit/62a6e478d619c6ce27cadec5d533ea207d9e0790&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="15470" author="alerner" created="Tue, 6 Jul 2010 21:05:20 +0000"  >&lt;p&gt;There&apos;s an important set of functionality that does not require linking libmongoclient and we would like to maintain the possibility of pulling all BSON out in an independent module. Let me pull the hot/cold portions apart and do some testing to see how consistently (or not) the inlining is happening. I&apos;ll be posting the commits to this item.&lt;/p&gt;

&lt;p&gt;By the way, excellent profiling work &amp;#8211; not only no this item, but in the whole BSON series items.  &lt;/p&gt;
</comment>
                            <comment id="15181" author="acm" created="Tue, 29 Jun 2010 13:48:00 +0000"  >&lt;p&gt;RE my comment about &apos;header-only&apos;, its clearly not the case that you can use all of the BSONObj methods without linking libmongoclient: BSONObj::jsonString, for instance, is not defined in the headers anywhere. So maybe rather than messing about with _&lt;em&gt;attribute&lt;/em&gt;_((noinline)) it would be better to just do the basic hot/cold partitioning and move the cold functions out-of-line into libmongoclient.&lt;/p&gt;
</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>4.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Tue, 6 Jul 2010 21:05:20 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        13 years, 31 weeks, 1 day ago
    
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_18254" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Dependencies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue><![CDATA[]]></customfieldvalue>


                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_10057" key="com.atlassian.jira.toolkit:lastusercommented">
                        <customfieldname>Last comment by Customer</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>true</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_10056" key="com.atlassian.jira.toolkit:lastupdaterorcommenter">
                        <customfieldname>Last commenter</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>ramon.fernandez@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            13 years, 31 weeks, 1 day ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                        <customfield id="customfield_10000" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Old_Backport</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10000"><![CDATA[No]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>alerner</customfieldvalue>
            <customfieldvalue>andrew.morrow@mongodb.com</customfieldvalue>
            <customfieldvalue>auto</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrpl13:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hrikkf:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>21984</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_23361" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Requested By</customfieldname>
                        <customfieldvalues>
                                

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10053" key="com.atlassian.jira.ext.charting:timeinstatus">
                        <customfieldname>Time In Status</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_22870" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Triagers</customfieldname>
                        <customfieldvalues>
                                

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_14350" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>serverRank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrkvt3:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                    </customfields>
    </item>
</channel>
</rss>