<!-- 
RSS generated by JIRA (8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d) at Wed Feb 07 20:52:29 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>OpenDaylight JIRA</title>
    <link>https://jira.opendaylight.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>8.20.10</version>
        <build-number>820010</build-number>
        <build-date>22-06-2022</build-date>
    </build-info>


<item>
            <title>[YANGTOOLS-177] Optimize generated range checks</title>
                <link>https://jira.opendaylight.org/browse/YANGTOOLS-177</link>
                <project id="10188" key="YANGTOOLS">yangtools</project>
                    <description>&lt;p&gt;Profiling cbench I have encountered performance overhead when constructing FlowCookie class &amp;#8211; 20528ms for 105187 invocations. Of that, 15894ms was spent in Range.closed() invocations.&lt;/p&gt;

&lt;p&gt;Looking at the generated code:&lt;/p&gt;

&lt;p&gt;    public FlowCookie(BigInteger _value) {&lt;br/&gt;
        if (_value != null) {&lt;br/&gt;
            boolean isValidRange = false;&lt;br/&gt;
            List&amp;lt;Range&amp;lt;BigInteger&amp;gt;&amp;gt; rangeConstraints = new ArrayList&amp;lt;&amp;gt;();&lt;br/&gt;
            rangeConstraints.add(Range.closed(new BigInteger(&quot;0&quot;), new BigInteger(&quot;18446744073709551615&quot;)));&lt;br/&gt;
            for (Range&amp;lt;BigInteger&amp;gt; r : rangeConstraints) {&lt;br/&gt;
                if (r.contains(_value)) &lt;/p&gt;
{
                isValidRange = true;
                }
&lt;p&gt;            }&lt;br/&gt;
            if (!isValidRange) &lt;/p&gt;
{
                throw new IllegalArgumentException(String.format(&quot;Invalid range: %s, expected: %s.&quot;, _value, rangeConstraints));
            }
&lt;p&gt;        }&lt;br/&gt;
        this._value = _value;&lt;br/&gt;
    }&lt;/p&gt;


&lt;p&gt;It is rather obvious we can do better:&lt;/p&gt;

&lt;p&gt;1) those range constraints should be lazily generated, but retained as static fields (double-checked loading)&lt;/p&gt;

&lt;p&gt;2) BigInteger(&quot;0&quot;) should be replaced with BigInteger.ZERO (also ONE and TEN)&lt;/p&gt;

&lt;p&gt;3) For values less that Long.MAX_VALUE, we should use BigInteger.valueOf(long)&lt;/p&gt;

&lt;p&gt;4) rangeConstraints should end up being an ImmutableList&lt;/p&gt;</description>
                <environment>&lt;p&gt;Operating System: All&lt;br/&gt;
Platform: All&lt;/p&gt;</environment>
        <key id="22597">YANGTOOLS-177</key>
            <summary>Optimize generated range checks</summary>
                <type id="10100" iconUrl="https://jira.opendaylight.org/secure/viewavatar?size=xsmall&amp;avatarId=10310&amp;avatarType=issuetype">Improvement</type>
                                                <status id="5" iconUrl="https://jira.opendaylight.org/images/icons/statuses/resolved.png" description="A resolution has been taken, and it is awaiting verification by reporter. From here issues are either reopened, or are closed.">Resolved</status>
                    <statusCategory id="3" key="done" colorName="green"/>
                                    <resolution id="10000">Done</resolution>
                                        <assignee username="lborak@cisco.com">Ladislav Borak</assignee>
                                    <reporter username="rovarga">Robert Varga</reporter>
                        <labels>
                    </labels>
                <created>Fri, 30 May 2014 21:25:30 +0000</created>
                <updated>Sun, 10 Apr 2022 18:35:07 +0000</updated>
                            <resolved>Fri, 1 Aug 2014 15:38:14 +0000</resolved>
                                                                        <due>Thu, 31 Jul 2014 00:00:00 +0000</due>
                            <votes>0</votes>
                                    <watches>7</watches>
                                                                                                                <comments>
                            <comment id="42772" author="mvitez@cisco.com" created="Wed, 11 Jun 2014 08:32:02 +0000"  >&lt;p&gt;Proposed patch: &lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://git.opendaylight.org/gerrit/#/c/7892/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://git.opendaylight.org/gerrit/#/c/7892/&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="42773" author="readams@readams.net" created="Tue, 8 Jul 2014 16:54:55 +0000"  >&lt;p&gt;It looks like the result of the code here is still incorrect.  This is attempting to do a double-checked lock pattern in an incorrect way with the Java memory model.  See &lt;a href=&quot;http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html&lt;/a&gt;&lt;br/&gt;
Here&apos;s the incorrect code:&lt;/p&gt;

&lt;p&gt;    public static List&amp;lt;Range&amp;lt;BigInteger&amp;gt;&amp;gt; length() {&lt;br/&gt;
        if (_length == null) {&lt;br/&gt;
            synchronized (org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.Name.class) {&lt;br/&gt;
                if (_length == null) &lt;/p&gt;
{
                    ImmutableList.Builder&amp;lt;Range&amp;lt;BigInteger&amp;gt;&amp;gt; builder = ImmutableList.builder();
                    builder.add(Range.closed(BigInteger.ONE, BigInteger.valueOf(256L)));
                    _length = builder.build();
                }
&lt;p&gt;            }&lt;br/&gt;
        }&lt;br/&gt;
        return _length;&lt;br/&gt;
    }&lt;/p&gt;

&lt;p&gt;In this case the (easy) correct fix is to use the static singleton pattern by declaring the _length field as a static variable in a subclass with a static initializer.  It will be automatically initialized on the first access just as the code here is attempting to do.&lt;/p&gt;</comment>
                            <comment id="42774" author="rovarga" created="Tue, 8 Jul 2014 18:18:29 +0000"  >&lt;p&gt;Agreed, that double-checked locking is my mistake (and now I have to hunt for all the paces I proliferated it). Not sure what an inner class will cost us in terms of memory overhead. We may need to do some profiling and tradeoff juggling.&lt;/p&gt;</comment>
                            <comment id="42775" author="readams@readams.net" created="Tue, 8 Jul 2014 18:25:06 +0000"  >&lt;p&gt;Given that this is a static variable the additional memory overhead is irrelevant. If you&apos;re doing this on an instance variable just setting it as volatile should fix your code.&lt;/p&gt;</comment>
                            <comment id="42776" author="rovarga" created="Tue, 8 Jul 2014 18:34:35 +0000"  >&lt;p&gt;So we have the following options:&lt;/p&gt;

&lt;p&gt;1) do proper locking by protecting the entire check in a synchronized block&lt;br/&gt;
2) make _length volatile&lt;br/&gt;
3) inner holder class&lt;br/&gt;
4) allocate eagerly at class load time&lt;/p&gt;

&lt;p&gt;I would opt for 3), except it may enlarge our PermGen footprint. I suspect we are usually very close to allocating an object when we touch the class, so 4) may actually make sense, too.&lt;/p&gt;

&lt;p&gt;Opinions?&lt;/p&gt;</comment>
                            <comment id="42777" author="rovarga" created="Tue, 8 Jul 2014 18:35:51 +0000"  >&lt;p&gt;Well, the holder is a class, which needs to be loaded into pergen and be left there. While it is insignificant overhead compared to objects, given that we have thousands of classes, that overhead may pile up.&lt;/p&gt;</comment>
                            <comment id="42778" author="readams@readams.net" created="Tue, 8 Jul 2014 18:37:46 +0000"  >&lt;p&gt;Oh I thought you&apos;d done the lazy initialization because you were benchmarking this.  If not, I&apos;d say just move the initialization to a static block pending some evidence that lazy loading is useful.&lt;/p&gt;</comment>
                            <comment id="42779" author="rovarga" created="Wed, 9 Jul 2014 09:55:47 +0000"  >&lt;p&gt;Thinking about this a bit more, we do not need any locking at all. The reasoning is the following:&lt;/p&gt;

&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;we are materializing immutable state, which is based solely on class bytecode&lt;/li&gt;
	&lt;li&gt;the encapsulating object is not referenced by individual instances&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;There are no ill side-effects from threads seeing different instances of the state &amp;#8211; since it is immutable, it is bound to behave the same. Since they are not referenced by instances, we are not running the risk of leaking multiple instances to the heap in general. Resolution of which instance will actually survive is amortized.&lt;/p&gt;

&lt;p&gt;Does this sounds correct, or am I missing something?&lt;/p&gt;</comment>
                            <comment id="42780" author="dkutenicsova" created="Fri, 25 Jul 2014 20:37:11 +0000"  >&lt;p&gt;+1 on removing double-check for null (it creates Findbug issue).&lt;/p&gt;</comment>
                            <comment id="42781" author="rovarga" created="Sat, 26 Jul 2014 11:14:12 +0000"  >&lt;p&gt;So let&apos;s lose the lazy initialization and perform it on class load, using normal constant field. That should cut the complexity.&lt;/p&gt;</comment>
                            <comment id="42782" author="lborak@cisco.com" created="Wed, 30 Jul 2014 22:03:51 +0000"  >&lt;p&gt;proposed patch: &lt;a href=&quot;https://git.opendaylight.org/gerrit/#/c/9483/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://git.opendaylight.org/gerrit/#/c/9483/&lt;/a&gt;&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10002">
                    <name>Duplicate</name>
                                                                <inwardlinks description="is duplicated by">
                                        <issuelink>
            <issuekey id="22606">YANGTOOLS-186</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                            <customfield id="customfield_11400" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                        <customfield id="customfield_10208" key="com.atlassian.jira.plugin.system.customfieldtypes:textfield">
                        <customfieldname>External issue ID</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1119</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10201" key="com.atlassian.jira.plugin.system.customfieldtypes:url">
                        <customfieldname>External issue URL</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue><![CDATA[https://bugs.opendaylight.org/show_bug.cgi?id=1119]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10204" key="com.atlassian.jira.plugin.system.customfieldtypes:select">
                        <customfieldname>ODL SR Target Milestone</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10370"><![CDATA[Helium]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                        <customfield id="customfield_10202" key="com.atlassian.jira.plugin.system.customfieldtypes:select">
                        <customfieldname>Priority</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10312"><![CDATA[High]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10000" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>0|i025m7:</customfieldvalue>

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