<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:41:08 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-1942] Reducing delegate allocations</title>
                <link>https://jira.mongodb.org/browse/CSHARP-1942</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;Hi!&lt;/p&gt;

&lt;p&gt;I would like to propose a couple of simple code changes that reduces amount of allocations, reducing GC load and increasing performance.&lt;br/&gt;
In one of our systems (an ASP.NET application with ~6GiB working set) the described sources of allocation account for ~2.2% of objects created.&lt;/p&gt;

&lt;p&gt;The first source of unnecessary allocations is the BsonSerializerRegistry.GetSerializer(Type) method. It uses the compiler-provided method group -&amp;gt; delegate conversion as concurrent dictionary object factory. Unfortunately, current compilers do not cache the created delegate, recreating it on every call (&lt;a href=&quot;https://github.com/dotnet/roslyn/issues/5835&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/dotnet/roslyn/issues/5835&lt;/a&gt;). The suggested fix is simple &amp;#8211; caching the delegate in member variable.&lt;/p&gt;

&lt;p&gt;The second source is a bit more complex. The BsonWriter allows for custom element name validation rules that potentially depend on the current element name. To implement this, the element name validator factory is represented as a delegate, that is changed when the associated state (stack/name) is changed. But, all three delegates (in PopElementNameValidator, PushElementNameValidator and WriteStartDocument) refer to an instance member (and even to a local variable) which makes them ineligible for caching. The proposed improvement replaces delegate-based validator creation with a more direct one.&lt;/p&gt;

&lt;p&gt;The benchmark code is available at &lt;a href=&quot;https://github.com/onyxmaster/mongobench&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/onyxmaster/mongobench&lt;/a&gt;.&lt;/p&gt;
</description>
                <environment></environment>
        <key id="364399">CSHARP-1942</key>
            <summary>Reducing delegate allocations</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="boris.dogadov@mongodb.com">Boris Dogadov</assignee>
                                    <reporter username="onyxmaster">Aristarkh Zagorodnikov</reporter>
                        <labels>
                    </labels>
                <created>Mon, 13 Mar 2017 21:06:05 +0000</created>
                <updated>Fri, 15 Jan 2021 16:56:33 +0000</updated>
                            <resolved>Wed, 13 Jan 2021 23:03:12 +0000</resolved>
                                    <version>2.4.3</version>
                                    <fixVersion>2.12.0</fixVersion>
                                    <component>Performance</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="3555364" author="JIRAUSER1257742" created="Fri, 8 Jan 2021 18:06:14 +0000"  >&lt;p&gt;Thanks &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=onyxmaster&quot; class=&quot;user-hover&quot; rel=&quot;onyxmaster&quot;&gt;onyxmaster&lt;/a&gt; for this contribution.&lt;br/&gt;
The similar optimization in BsonWriter.cs is applied&#160;&lt;a href=&quot;https://github.com/BorisDog/mongo-csharp-driver/commit/7c3c5caf53366c16df1bf0108e20b674c0b5647f&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The optimization in BsonSerializerRegistry.cs looks good. Could you please rebase and leave the BsonSerializerRegistry.cs changes?&lt;/p&gt;</comment>
                            <comment id="3518694" author="onyxmaster" created="Mon, 7 Dec 2020 16:07:41 +0000"  >&lt;p&gt;I wonder why would you close an older issue (from 2017) as a duplicate of a newer one (from 2019) instead of vice versa, even when the newer one contains neither a better description of the issue nor a better solution (the PR in the second issue does not deal with the root of the issue, the delegate could be removed altogether), while also not covering one of the issues (see BsonSerializerRegistry).&lt;/p&gt;</comment>
                            <comment id="1523037" author="onyxmaster" created="Mon, 13 Mar 2017 21:31:43 +0000"  >&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;BenchmarkDotNet=v0.10.3.0, OS=Microsoft Windows NT 6.2.9200.0&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;Processor=Intel(R) Core(TM) i7-4810MQ CPU 2.80GHz, ProcessorCount=8&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;Frequency=2728058 Hz, Resolution=366.5611 ns, Timer=TSC&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;  [Host]     : Clr 4.0.30319.42000, 64bit RyuJIT-v4.6.1586.0&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;  Job-MXQTWF : Clr 4.0.30319.42000, 64bit RyuJIT-v4.6.1586.0&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&amp;nbsp;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;Jit=RyuJit  Platform=X64  Force=False  &lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;Server=True  &lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;
&lt;p&gt;Before:&lt;/p&gt;
&lt;div class=&apos;table-wrap&apos;&gt;
&lt;table class=&apos;confluenceTable&apos;&gt;&lt;tbody&gt;
&lt;tr&gt;
&lt;td class=&apos;confluenceTd&apos;&gt;       Method &lt;/td&gt;
&lt;td class=&apos;confluenceTd&apos;&gt;        Mean &lt;/td&gt;
&lt;td class=&apos;confluenceTd&apos;&gt;    StdDev &lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=&apos;confluenceTd&apos;&gt; WriteMessage &lt;/td&gt;
&lt;td class=&apos;confluenceTd&apos;&gt; 440.3268 ns &lt;/td&gt;
&lt;td class=&apos;confluenceTd&apos;&gt; 2.5639 ns &lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=&apos;confluenceTd&apos;&gt; GetSerializer &lt;/td&gt;
&lt;td class=&apos;confluenceTd&apos;&gt; 50.0609 ns &lt;/td&gt;
&lt;td class=&apos;confluenceTd&apos;&gt; 0.3526 ns &lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;


&lt;p&gt;After:&lt;/p&gt;
&lt;div class=&apos;table-wrap&apos;&gt;
&lt;table class=&apos;confluenceTable&apos;&gt;&lt;tbody&gt;
&lt;tr&gt;
&lt;td class=&apos;confluenceTd&apos;&gt;       Method &lt;/td&gt;
&lt;td class=&apos;confluenceTd&apos;&gt;        Mean &lt;/td&gt;
&lt;td class=&apos;confluenceTd&apos;&gt;    StdDev &lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=&apos;confluenceTd&apos;&gt; WriteMessage &lt;/td&gt;
&lt;td class=&apos;confluenceTd&apos;&gt; 397.6803 ns &lt;/td&gt;
&lt;td class=&apos;confluenceTd&apos;&gt; 3.8869 ns &lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=&apos;confluenceTd&apos;&gt; GetSerializer &lt;/td&gt;
&lt;td class=&apos;confluenceTd&apos;&gt; 42.8741 ns &lt;/td&gt;
&lt;td class=&apos;confluenceTd&apos;&gt; 0.4082 ns &lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
</comment>
                            <comment id="1523024" author="onyxmaster" created="Mon, 13 Mar 2017 21:09:59 +0000"  >&lt;p&gt;&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/pull/273&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/pull/273&lt;/a&gt;&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                            <outwardlinks description="duplicates">
                                        <issuelink>
            <issuekey id="684668">CSHARP-2504</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <attachments>
                            <attachment id="290133" name="Current.jpg" size="100202" author="boris.dogadov@mongodb.com" created="Fri, 4 Dec 2020 17:59:14 +0000"/>
                            <attachment id="290134" name="Optimized.jpg" size="82508" author="boris.dogadov@mongodb.com" created="Fri, 4 Dec 2020 17:59:20 +0000"/>
                            <attachment id="295201" name="image-2021-01-13-10-25-42-111.png" size="42945" author="boris.dogadov@mongodb.com" created="Wed, 13 Jan 2021 18:25:43 +0000"/>
                            <attachment id="295205" name="image-2021-01-13-10-30-34-813.png" size="66110" author="boris.dogadov@mongodb.com" created="Wed, 13 Jan 2021 18:30:36 +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|hrb4xr:</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>