<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:21:40 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>[CDRIVER-4697] More efficient trace toggle</title>
                <link>https://jira.mongodb.org/browse/CDRIVER-4697</link>
                <project id="10030" key="CDRIVER">C Driver</project>
                    <description>&lt;p&gt;I enjoy using trace option in libmongoc.&lt;/p&gt;

&lt;p&gt;But I see that trace is toggled via compiler directive. Since we plan to build libmongoc with trace enabled, the trace data is always prepared, but eventually later not output if trace is disabled.&lt;/p&gt;

&lt;p&gt;This could be done more optimized by checking a global variable instead of compiler switch.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Expected:&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;Optimize trace toggle in &lt;a href=&quot;https://github.com/mongodb/mongo-c-driver/blob/master/src/libmongoc/src/mongoc/mongoc-trace-private.h#L36&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;mongoc-trace-private.h&lt;/a&gt; by updating&lt;/p&gt;
&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;   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;if (MONGOC_TRACE_ENABLED)&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;to&lt;/p&gt;
&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;   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;if (MONGOC_TRACE_ENABLED &amp;amp;&amp;amp; gLogTrace)&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;ul&gt;
	&lt;li&gt;MONGOC_TRACE_ENABLED is a compile time flag.&lt;/li&gt;
	&lt;li&gt;If it is MONGOC_TRACE_ENABLED to false, the compiler can optimize away the whole code black inside if statement.&lt;/li&gt;
	&lt;li&gt;&lt;b&gt;Note&lt;/b&gt;: We also have a similar function -&#160; &lt;a href=&quot;https://github.com/vector-of-bool/mongo-c-driver/blob/master/src/libmongoc/src/mongoc/mongoc-log.c#L64&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;_mongoc_log_trace_is_enabled&lt;/a&gt;&#160;&lt;/li&gt;
&lt;/ul&gt;
</description>
                <environment></environment>
        <key id="2398560">CDRIVER-4697</key>
            <summary>More efficient trace toggle</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</type>
                                            <priority id="4" iconUrl="https://jira.mongodb.org/images/icons/priorities/minor.svg">Minor - P4</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="support@monkeybreadsoftware.de">Christian Schmitz</reporter>
                        <labels>
                            <label>feature-request</label>
                            <label>neweng</label>
                    </labels>
                <created>Sat, 22 Jul 2023 09:14:43 +0000</created>
                <updated>Mon, 5 Feb 2024 17:30:00 +0000</updated>
                                                                            <component>libmongoc</component>
                    <component>Logging</component>
                                        <votes>0</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="5604157" author="JIRAUSER1269924" created="Tue, 1 Aug 2023 09:00:28 +0000"  >&lt;p&gt;Understood, thank you for the clarification!&#160;&lt;/p&gt;</comment>
                            <comment id="5595772" author="JIRAUSER1274498" created="Thu, 27 Jul 2023 15:29:53 +0000"  >&lt;p&gt;Well, technically you could call &#160;_mongoc_log_trace_is_enabled() function.&lt;/p&gt;

&lt;p&gt;But I still prefer to use&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;&#160;if (MONGOC_TRACE_ENABLED &amp;amp;&amp;amp; gLogTrace)&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;since the compiler can optimize the whole if away, if MONGOC_TRACE_ENABLED is not 1.&lt;/p&gt;

&lt;p&gt;If MONGOC_TRACE_ENABLED is 1 (as for our builds), reading the boolean variable should be quick and have nearly no performance impact. The whole thing avoids building the debug message when trace is not enabled.&lt;/p&gt;</comment>
                            <comment id="5594677" author="JIRAUSER1269924" created="Thu, 27 Jul 2023 08:26:55 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=support%40monkeybreadsoftware.de&quot; class=&quot;user-hover&quot; rel=&quot;support@monkeybreadsoftware.de&quot;&gt;support@monkeybreadsoftware.de&lt;/a&gt;, thanks for your suggestion.&lt;br/&gt;
If I understand correctly, you&apos;re suggesting to add&#160; &lt;a href=&quot;https://github.com/vector-of-bool/mongo-c-driver/blob/master/src/libmongoc/src/mongoc/mongoc-log.c#L64&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;_mongoc_log_trace_is_enabled&lt;/a&gt; check in &lt;a href=&quot;https://github.com/mongodb/mongo-c-driver/blob/master/src/libmongoc/src/mongoc/mongoc-trace-private.h#L36&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;mongoc-trace-private.h&lt;/a&gt;, additional to &lt;a href=&quot;https://github.com/vector-of-bool/mongo-c-driver/blob/master/src/libmongoc/src/mongoc/mongoc-log.c#L106&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;mongoc_log&lt;/a&gt;. In other words, making the check early whether tracing is enabled and trace messages are toggled on. Is this correct understanding?&lt;/p&gt;</comment>
                            <comment id="5584412" author="JIRAUSER1274498" created="Sat, 22 Jul 2023 09:19:16 +0000"  >&lt;p&gt;In mongoc-trace-private.h, you see&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;if (MONGOC_TRACE_ENABLED)&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;so if the library is compiled with tracing, the block below will run.&lt;/p&gt;

&lt;p&gt;But if tracing is disabled, we do all the log calls and potential also convert bson to text to include it.&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;My suggestion is to change this to:&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;&#160;if (MONGOC_TRACE_ENABLED &amp;amp;&amp;amp; gLogTrace)&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;So the trace code only runs if enabled. We keep MONGOC_TRACE_ENABLED, so the compiler can optimize away the whole block if MONGOC_TRACE_ENABLED is false. But if it is true, it check the gLogTrace variable.&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;This variable must be declared of course:&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;extern bool gLogTrace;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;and Made non-static in mongoc-log.c. Maybe also rename it as it is now in the global namespace.&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;We have built library with this changes. Performance with trace enabled for building the library and then having trace disabled should be about the same as if you would build library with log disabled.&lt;/p&gt;</comment>
                            <comment id="5584410" author="dbeng-pm-bot" created="Sat, 22 Jul 2023 09:14:46 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=support%40monkeybreadsoftware.de&quot; class=&quot;user-hover&quot; rel=&quot;support@monkeybreadsoftware.de&quot;&gt;support@monkeybreadsoftware.de&lt;/a&gt;, thank you for reporting this issue! The team will look into it and get back to you soon. &lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="2529840">CDRIVER-4800</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <attachments>
                    </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_10857" key="com.pyxis.greenhopper.jira:gh-epic-link">
                        <customfieldname>Epic Link</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>CDRIVER-3775</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_21553" key="com.atlassian.jira.plugin.system.customfieldtypes:labels">
                        <customfieldname>Quarter</customfieldname>
                        <customfieldvalues>
                                        <label>FY25Q1</label>
    
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|i2172o:</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>