<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:59:20 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>[JAVA-3328] Excessive memory allocation due to unwrapping of updates in bulk ops</title>
                <link>https://jira.mongodb.org/browse/JAVA-3328</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;It looks like the changes in&#160;332ffc78538b36db880c94836d82276f5e5d9296 introduced a call to isEmpty() on the update document, to throw an illegal arg exception if the update document is empty.&lt;/p&gt;

&lt;p&gt;However, when used with BsonDocumentWrapper, the call to isEmpty() causes the wrapped document to be unwrapped, just to check for emptiness. This causes many unnecessary allocations when unwrapping update documents of any size.&lt;/p&gt;

&lt;p&gt;Removing this call saves about approx ~80% GC&apos;d allocations for a comparable volume of writes, as illustrated in the attached screenshot comparing two JProfiler snapshots. On the left is the version w/o the check, on the right is the current code w/ the check.&lt;/p&gt;</description>
                <environment></environment>
        <key id="806965">JAVA-3328</key>
            <summary>Excessive memory allocation due to unwrapping of updates in bulk ops</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</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="13201">Fixed</resolution>
                                        <assignee username="jeff.yemin@mongodb.com">Jeffrey Yemin</assignee>
                                    <reporter username="oleg@evergage.com">Oleg Rekutin</reporter>
                        <labels>
                    </labels>
                <created>Tue, 18 Jun 2019 21:23:42 +0000</created>
                <updated>Sat, 28 Oct 2023 11:22:11 +0000</updated>
                            <resolved>Wed, 24 Jul 2019 01:11:19 +0000</resolved>
                                    <version>3.6.0</version>
                    <version>3.7.0</version>
                    <version>3.8.0</version>
                    <version>3.9.0</version>
                    <version>3.10.0</version>
                                    <fixVersion>3.11.0</fixVersion>
                                    <component>Write Operations</component>
                                        <votes>1</votes>
                                    <watches>3</watches>
                                                                                                                <comments>
                            <comment id="2354853" author="xgen-internal-githook" created="Thu, 1 Aug 2019 18:55:55 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;Jeff Yemin&apos;, &apos;email&apos;: &apos;jeff.yemin@10gen.com&apos;, &apos;username&apos;: &apos;jyemin&apos;}
&lt;p&gt;Message: Optimize check for an empty update document&lt;/p&gt;

&lt;p&gt;The CRUD specification requires that an update contains at least one&lt;br/&gt;
field, in order to check for application bugs.  Because once the command&lt;br/&gt;
makes it to the server it can&apos;t be distinguished from a replace (where&lt;br/&gt;
an empty document is legal).&lt;/p&gt;

&lt;p&gt;The current method of checking for an empty document is to call&lt;br/&gt;
BsonDocument#isEmpty.  But that has the unfortunate affect of hydrating&lt;br/&gt;
a BsonDocumentWrapper into a full BsonDocument.  We really want to avoid&lt;br/&gt;
that hit.  To do so, we need another way of checking for an empty&lt;br/&gt;
document.  We use the technique of wrapping the BsonWriter with a&lt;br/&gt;
FieldTracking BsonWriter, which tracks whether at least one field&lt;br/&gt;
is written.  BulkWriteBatch then checks that and throws if it&apos;s not.&lt;/p&gt;

&lt;p&gt;This also fixes a bug in which that check was done for both update and&lt;br/&gt;
replace requests.  An empty replace document, while rare, is legal.&lt;/p&gt;

&lt;p&gt;Thanks to @astral303 for finding this issue and for opening an initial&lt;br/&gt;
PR that provided inspiration for this fix.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-3328&quot; title=&quot;Excessive memory allocation due to unwrapping of updates in bulk ops&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-3328&quot;&gt;&lt;del&gt;JAVA-3328&lt;/del&gt;&lt;/a&gt;&lt;br/&gt;
Branch: mongot&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/commit/6d207815a4e627abe8227791837c9746d45b78f2&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/6d207815a4e627abe8227791837c9746d45b78f2&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="2354852" author="xgen-internal-githook" created="Thu, 1 Aug 2019 18:55:51 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;Jeff Yemin&apos;, &apos;email&apos;: &apos;jeff.yemin@10gen.com&apos;, &apos;username&apos;: &apos;jyemin&apos;}
&lt;p&gt;Message: Introduce BsonWriterDecorator superclass&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-3328&quot; title=&quot;Excessive memory allocation due to unwrapping of updates in bulk ops&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-3328&quot;&gt;&lt;del&gt;JAVA-3328&lt;/del&gt;&lt;/a&gt;&lt;br/&gt;
Branch: mongot&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/commit/b744eff936e090de931b0f7713437881cda8bb14&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/b744eff936e090de931b0f7713437881cda8bb14&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="2340185" author="xgen-internal-githook" created="Wed, 24 Jul 2019 01:11:14 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;Jeff Yemin&apos;, &apos;username&apos;: &apos;jyemin&apos;, &apos;email&apos;: &apos;jeff.yemin@10gen.com&apos;}
&lt;p&gt;Message: Optimize check for an empty update document&lt;/p&gt;

&lt;p&gt;The CRUD specification requires that an update contains at least one&lt;br/&gt;
field, in order to check for application bugs.  Because once the command&lt;br/&gt;
makes it to the server it can&apos;t be distinguished from a replace (where&lt;br/&gt;
an empty document is legal).&lt;/p&gt;

&lt;p&gt;The current method of checking for an empty document is to call&lt;br/&gt;
BsonDocument#isEmpty.  But that has the unfortunate affect of hydrating&lt;br/&gt;
a BsonDocumentWrapper into a full BsonDocument.  We really want to avoid&lt;br/&gt;
that hit.  To do so, we need another way of checking for an empty&lt;br/&gt;
document.  We use the technique of wrapping the BsonWriter with a&lt;br/&gt;
FieldTracking BsonWriter, which tracks whether at least one field&lt;br/&gt;
is written.  BulkWriteBatch then checks that and throws if it&apos;s not.&lt;/p&gt;

&lt;p&gt;This also fixes a bug in which that check was done for both update and&lt;br/&gt;
replace requests.  An empty replace document, while rare, is legal.&lt;/p&gt;

&lt;p&gt;Thanks to @astral303 for finding this issue and for opening an initial&lt;br/&gt;
PR that provided inspiration for this fix.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-3328&quot; title=&quot;Excessive memory allocation due to unwrapping of updates in bulk ops&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-3328&quot;&gt;&lt;del&gt;JAVA-3328&lt;/del&gt;&lt;/a&gt;&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/commit/6d207815a4e627abe8227791837c9746d45b78f2&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/6d207815a4e627abe8227791837c9746d45b78f2&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="2340184" author="xgen-internal-githook" created="Wed, 24 Jul 2019 01:11:12 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;Jeff Yemin&apos;, &apos;username&apos;: &apos;jyemin&apos;, &apos;email&apos;: &apos;jeff.yemin@10gen.com&apos;}
&lt;p&gt;Message: Introduce BsonWriterDecorator superclass&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-3328&quot; title=&quot;Excessive memory allocation due to unwrapping of updates in bulk ops&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-3328&quot;&gt;&lt;del&gt;JAVA-3328&lt;/del&gt;&lt;/a&gt;&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/commit/b744eff936e090de931b0f7713437881cda8bb14&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/b744eff936e090de931b0f7713437881cda8bb14&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="2289159" author="oleg@evergage.com" created="Tue, 18 Jun 2019 22:45:46 +0000"  >&lt;p&gt;Added pull request and a benchmark you can run yourself w/ memory allocation profiling. &lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/pull/515&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/pull/515&lt;/a&gt;&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                            <attachment id="221279" name="Screen Shot 2019-06-18 at 5.21.28 PM.png" size="1796339" author="oleg@evergage.com" created="Tue, 18 Jun 2019 21:23:34 +0000"/>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                        <customfield id="customfield_10011" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Backwards Compatibility</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10038"><![CDATA[Fully Compatible]]></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_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hr7d9r:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9223372036854775807</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>