<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:42:44 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>[CSHARP-2505] Reduce array allocations in BsonStreamAdapter</title>
                <link>https://jira.mongodb.org/browse/CSHARP-2505</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;BsonStreamAdapter already uses some kind of an array reuse concept using the _tempUtf8 variable. This approach could, however, be significantly improved by dropping this helper variable and instead switching to System.Buffers.ArrayPool&amp;lt;byte&amp;gt;. The reason being that e.g. for the UTF8 conversions in WriteString() and WriteCString, the buffers are only needed for a very short time and can immediately (at the end of the very same method) be returned back to the pool once the buffer has been written into the output stream.&lt;/p&gt;</description>
                <environment></environment>
        <key id="684669">CSHARP-2505</key>
            <summary>Reduce array allocations in BsonStreamAdapter</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="10038" iconUrl="https://jira.mongodb.org/images/icons/subtask.gif" description="">Backlog</status>
                    <statusCategory id="2" key="new" colorName="default"/>
                                    <resolution id="-1">Unresolved</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="daniel.hegener@gmx.net">Daniel Hegener</reporter>
                        <labels>
                    </labels>
                <created>Wed, 6 Feb 2019 13:00:48 +0000</created>
                <updated>Thu, 8 Jun 2023 15:46:00 +0000</updated>
                                            <version>2.7.3</version>
                                                    <component>Performance</component>
                    <component>Serialization</component>
                                        <votes>0</votes>
                                    <watches>1</watches>
                                                                                                                <comments>
                            <comment id="2145660" author="JIRAUSER1256534" created="Tue, 12 Feb 2019 11:10:32 +0000"  >&lt;p&gt;I was thinking about how to implement this and came up with a bunch of options:&lt;/p&gt;

&lt;p&gt;1) Simply increase the length of the existing _tempUtf8 array to something considerably bigger than its current length of 128 bytes. This would probably not hurt in any noticeable way and it would reduce memory allocations for documents that contain &quot;larger&quot; strings. But it would not eliminate the memory problem in cases of &quot;really large&quot; strings (as in strings too long to fit into the increased _tempUtf8 buffer).&lt;/p&gt;

&lt;p&gt;2) Reference System.Buffers (which would be a new dependency) and then&lt;/p&gt;

&lt;p&gt;&#160; &#160; a) replace the _tempUtf8 buffer completely with an ArrayPool&amp;lt;byte&amp;gt;.Shared.Rent&apos;ed buffer. I personally like the cleanliness of this approach but (beyond adding a new dependency) it introduces a little overhead (ArrayPool e.g. does some magic to ensure thread-safety)&lt;/p&gt;

&lt;p&gt;&#160; &#160; b) keep the _tempUtf8 buffer but use the ArrayPool approach only for all places where we currently do a &quot;new byte&lt;span class=&quot;error&quot;&gt;&amp;#91;some length&amp;#93;&lt;/span&gt;&quot; call. This would increase the complexity of the code a little and would still keep the optimization for small strings using the hardcoded limit of 128 bytes which feels a bit arbitrary.&lt;/p&gt;

&lt;p&gt;3) A combination of 1 and 2b where the _tempUt8 buffer would be increased and only for even larger strings the ArrayPool concept would kick in.&lt;/p&gt;

&lt;p&gt;4) Some magic hand-written ArrayPool implementation which would not force us to reference System.Buffers and which could be fine-tuned.&lt;/p&gt;

&lt;p&gt;Comments anyone?&lt;/p&gt;</comment>
                            <comment id="2139374" author="JIRAUSER1256534" created="Wed, 6 Feb 2019 13:02:12 +0000"  >&lt;p&gt;Here is the corresponding profiler output after the serialization of 2m+ complex documents:&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://jira.mongodb.org/secure/attachment/208233/208233_image-2019-02-06-14-01-41-774.png&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt;&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                                                <inwardlinks description="is related to">
                                                        </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <attachments>
                            <attachment id="208233" name="image-2019-02-06-14-01-41-774.png" size="55172" author="dnickless" created="Wed, 6 Feb 2019 13:01:42 +0000"/>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                    <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|hub7z3:</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>