<!-- 
RSS generated by JIRA (9.12.2#9120002-sha1:301bf498dd45d800842af0b84230f1bb58606c13) at Sun Jan 12 12:23:36 UTC 2025

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>Mojang Studios Jira</title>
    <link>https://bugs.mojang.com</link>
    <description>This file is an XML representation of an issue</description>
    <language>en</language>    <build-info>
        <version>9.12.2</version>
        <build-number>9120002</build-number>
        <build-date>10-01-2024</build-date>
    </build-info>


<item>
            <title>[MC-10204] MemoryConnection has an extremly poor collection choice</title>
                <link>https://bugs.mojang.com/browse/MC-10204</link>
                <project id="10400" key="MC">Minecraft: Java Edition</project>
                    <description>&lt;p&gt;I&apos;m sure these variables have other names internal to minecraft, but i&apos;ll refer to them by their MCP name.&lt;/p&gt;

&lt;p&gt;readPacketCache is a synchronized array list. Items are removed from it in a read function by readPacketCache.remove(0). This a) blocks all access to the object and b) causes every element to be copied into a lower index, making this an order N operation. &lt;br/&gt;
This makes reading N items from the &quot;queue&quot; an O(N^2) operation, holding a lock for each O(N) operation.&lt;br/&gt;
This means that under high load, insert to the queue is an O(N) operation, with a high overhead, while it waits for the lock.&lt;/p&gt;

&lt;p&gt;the java concurrentLinkedQueue is an unbounded queue designed for exactly this situation with constant time, lock-free push/pull concurrently (several threads can push and pull at the same time without causing any of them to block).&lt;/p&gt;

&lt;p&gt;Changing this code does not cause any other code to need to be changed, as it is a private variable, and INetworkManager&apos;s are ALWAYS accessed via their interface, because it could be a Memory or a TCP connection, and the code doesn&apos;t know which.&lt;/p&gt;

&lt;p&gt;this is cross-posted as a patch to fml - &lt;a href=&quot;https://github.com/MinecraftForge/FML/issues/189&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/MinecraftForge/FML/issues/189&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have tested this in my MCP install, with both buildcraft and other mods active, with no problems.&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;&lt;span class=&quot;code-keyword&quot;&gt;package&lt;/span&gt; net.minecraft.network;

&lt;span class=&quot;code-keyword&quot;&gt;import&lt;/span&gt; java.io.IOException;
&lt;span class=&quot;code-keyword&quot;&gt;import&lt;/span&gt; java.net.InetSocketAddress;
&lt;span class=&quot;code-keyword&quot;&gt;import&lt;/span&gt; java.net.SocketAddress;
&lt;span class=&quot;code-keyword&quot;&gt;import&lt;/span&gt; java.util.Queue;
&lt;span class=&quot;code-keyword&quot;&gt;import&lt;/span&gt; java.util.concurrent.ConcurrentLinkedQueue;

&lt;span class=&quot;code-keyword&quot;&gt;import&lt;/span&gt; net.minecraft.network.packet.NetHandler;
&lt;span class=&quot;code-keyword&quot;&gt;import&lt;/span&gt; net.minecraft.network.packet.Packet;

&lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;class &lt;/span&gt;MemoryConnection &lt;span class=&quot;code-keyword&quot;&gt;implements&lt;/span&gt; INetworkManager
{
    &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;final&lt;/span&gt; SocketAddress mySocketAddress = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; InetSocketAddress(&lt;span class=&quot;code-quote&quot;&gt;&quot;127.0.0.1&quot;&lt;/span&gt;, 0);
    &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;final&lt;/span&gt; Queue&amp;lt;Packet&amp;gt; readPacketCache = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; ConcurrentLinkedQueue&amp;lt;Packet&amp;gt;();
    &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; MemoryConnection pairedConnection;
    &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; NetHandler myNetHandler;

    &lt;span class=&quot;code-comment&quot;&gt;/** set to &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt; by {server,network}Shutdown */&lt;/span&gt;
    &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;code-object&quot;&gt;boolean&lt;/span&gt; shuttingDown = &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;
    &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;code-object&quot;&gt;String&lt;/span&gt; shutdownReason = &quot;&quot;;
    &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;code-object&quot;&gt;Object&lt;/span&gt;[] field_74439_g;
    &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;code-object&quot;&gt;boolean&lt;/span&gt; gamePaused = &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;

&amp;lt;snip - unchanged functions removed&amp;gt;
    /**
     * Checks timeouts and processes all pending read packets.
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; void processReadPackets()
    {
        &lt;span class=&quot;code-object&quot;&gt;int&lt;/span&gt; var1 = 2500;

        &lt;span class=&quot;code-keyword&quot;&gt;while&lt;/span&gt; (var1-- &amp;gt;= 0 &amp;amp;&amp;amp; !&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;.readPacketCache.isEmpty())
        {
            Packet var2 = &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;.readPacketCache.poll();
            var2.processPacket(&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;.myNetHandler);
        }

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;.readPacketCache.size() &amp;gt; var1)
        {
            &lt;span class=&quot;code-object&quot;&gt;System&lt;/span&gt;.out.println(&lt;span class=&quot;code-quote&quot;&gt;&quot;Memory connection overburdened; after processing 2500 packets, we still have &quot;&lt;/span&gt; + &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;.readPacketCache.size() + &lt;span class=&quot;code-quote&quot;&gt;&quot; to go!&quot;&lt;/span&gt;);
        }

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;.shuttingDown &amp;amp;&amp;amp; &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;.readPacketCache.isEmpty())
        {
            &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;.myNetHandler.handleErrorMessage(&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;.shutdownReason, &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;.field_74439_g);
        }
    }
&amp;lt;snip - more unchanged functions removed&amp;gt;
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;--

@@ -7,7 +7,7 @@
 &lt;span class=&quot;code-keyword&quot;&gt;import&lt;/span&gt; java.net.InetSocketAddress;
 &lt;span class=&quot;code-keyword&quot;&gt;import&lt;/span&gt; java.net.SocketAddress;
-&lt;span class=&quot;code-keyword&quot;&gt;import&lt;/span&gt; java.util.ArrayList;
-&lt;span class=&quot;code-keyword&quot;&gt;import&lt;/span&gt; java.util.Collections;
-&lt;span class=&quot;code-keyword&quot;&gt;import&lt;/span&gt; java.util.List;
+&lt;span class=&quot;code-keyword&quot;&gt;import&lt;/span&gt; java.util.Queue;
+&lt;span class=&quot;code-keyword&quot;&gt;import&lt;/span&gt; java.util.concurrent.ConcurrentLinkedQueue;
+
 &lt;span class=&quot;code-keyword&quot;&gt;import&lt;/span&gt; net.minecraft.network.packet.NetHandler;
 &lt;span class=&quot;code-keyword&quot;&gt;import&lt;/span&gt; net.minecraft.network.packet.Packet;
@@ -16,5 +16,5 @@
 {
     &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;final&lt;/span&gt; SocketAddress mySocketAddress = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; InetSocketAddress(&lt;span class=&quot;code-quote&quot;&gt;&quot;127.0.0.1&quot;&lt;/span&gt;, 0);
-    &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;final&lt;/span&gt; List readPacketCache = Collections.synchronizedList(&lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; ArrayList());
+    &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;final&lt;/span&gt; Queue&amp;lt;Packet&amp;gt; readPacketCache = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; ConcurrentLinkedQueue&amp;lt;Packet&amp;gt;();
     &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; MemoryConnection pairedConnection;
     &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; NetHandler myNetHandler;
@@ -77,5 +77,5 @@
         &lt;span class=&quot;code-keyword&quot;&gt;while&lt;/span&gt; (var1-- &amp;gt;= 0 &amp;amp;&amp;amp; !&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;.readPacketCache.isEmpty())
         {
-            Packet var2 = (Packet)&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;.readPacketCache.remove(0);
+            Packet var2 = &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;.readPacketCache.poll();
             var2.processPacket(&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;.myNetHandler);
         }
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</description>
                <environment></environment>
        <key id="24085">MC-10204</key>
            <summary>MemoryConnection has an extremly poor collection choice</summary>
                <type id="1" iconUrl="https://bugs.mojang.com/secure/viewavatar?size=xsmall&amp;avatarId=18903&amp;avatarType=issuetype">Bug</type>
                                    <status id="5" iconUrl="https://bugs.mojang.com/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="success"/>
                                    <resolution id="4">Incomplete</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="aart bluestoke">Andrew Hill</reporter>
                        <labels>
                            <label>cpu</label>
                            <label>performance</label>
                            <label>singleplayer</label>
                    </labels>
                <created>Sat, 23 Feb 2013 23:48:40 +0100</created>
                <updated>Fri, 18 Mar 2016 17:05:50 +0100</updated>
                            <resolved>Fri, 18 Mar 2016 17:05:50 +0100</resolved>
                                    <version>Minecraft 1.4.7</version>
                    <version>Minecraft 1.5</version>
                                                                        <votes>7</votes>
                                    <watches>5</watches>
                                                                            <comments>
                            <comment id="295333" author="JIRAUSER71590" created="Fri, 18 Mar 2016 17:05:44 +0100"  >&lt;p&gt;No response for over a year.&lt;/p&gt;</comment>
                            <comment id="205305" author="galaxy_2alex" created="Sat, 25 Oct 2014 14:01:19 +0200"  >&lt;p&gt;Is this still a concern in the &lt;em&gt;current Minecraft version&lt;/em&gt; &lt;b&gt;1.8.1 Prerelease 3&lt;/b&gt; / Launcher version &lt;b&gt;1.5.3&lt;/b&gt; or later? If so, please &lt;em&gt;update the affected versions&lt;/em&gt; in order to best aid Mojang ensuring bugs are still valid in the latest releases/pre-releases.&lt;/p&gt;</comment>
                            <comment id="151377" author="bugi74" created="Wed, 16 Apr 2014 19:16:33 +0200"  >&lt;p&gt;Considering that there is now another bug for getting exceptions with single player mode, apparently caused by firewall blocking localhost connection, it would seem that the memory connection might not be currently used. However, I haven&apos;t checked this assumption. And without access to an up to date MCP, I can not confirm the situation in any meaningful way. (Or well, I could, but it would take hours, while Mojang could both check and fix this in less than few minutes... so... yeah, better ask Mojang about the status.)&lt;/p&gt;</comment>
                            <comment id="148748" author="jar_" created="Mon, 24 Mar 2014 00:25:49 +0100"  >&lt;p&gt;Is this still a concern in the &lt;em&gt;current Minecraft version&lt;/em&gt; &lt;b&gt;14w11b&lt;/b&gt; / Launcher version &lt;b&gt;1.3.11&lt;/b&gt; or later? If so, please &lt;em&gt;update the affected versions&lt;/em&gt; in order to best aid Mojang ensuring bugs are still valid in the latest releases/pre-releases.&lt;/p&gt;</comment>
                            <comment id="55317" author="bugi74" created="Tue, 19 Mar 2013 00:57:10 +0100"  >&lt;p&gt;Still valid for 1.5 (has the same piece of code).&lt;/p&gt;</comment>
                            <comment id="49106" author="torabi" created="Sat, 2 Mar 2013 17:31:21 +0100"  >&lt;p&gt;Pretty sure performance issues due to poor implementation qualifies as a bug. In the case of this issue in particular, fixing it may help with some of the ghosting or desynch type of issues people keep encountering.&lt;/p&gt;</comment>
                            <comment id="47351" author="kumasasa" created="Sun, 24 Feb 2013 09:01:36 +0100"  >&lt;p&gt;Reopened.&lt;br/&gt;
Technically still not a bug, but now your change is small enough that a dev can look at it.&lt;/p&gt;</comment>
                            <comment id="47342" author="aart bluestoke" created="Sun, 24 Feb 2013 04:36:46 +0100"  >&lt;p&gt;@Dean Baset  -  i have removed all non-relevent code;  that code was present in the full source i showed; that is because, as a non-minecraft dev, that is all i have easy access to, and this started as a cross-post from the FML github.&lt;/p&gt;

&lt;p&gt;That was why I also posted the patch, which is a 5 line change which, other than variable names, would apply straight to vanilla code.&lt;/p&gt;

&lt;p&gt;@Kumasasa - where would be the appropriate place to raise an issue like this? (also, this implies that you do not consider easily fixed excessive cpu usage a bug?)&lt;/p&gt;</comment>
                            <comment id="47333" author="kumasasa" created="Sun, 24 Feb 2013 03:29:38 +0100"  >&lt;p&gt;Wrapped the code with &lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;But in the sense of this bug tracker, this is no bug, thus invalid.&lt;/p&gt;
</comment>
                            <comment id="47323" author="unon1100" created="Sun, 24 Feb 2013 02:34:55 +0100"  >&lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt;import cpw.mods.fml.common.network.FMLNetworkHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Really? Using third-party programs in your &quot;fix&quot; code? C&apos;mon, man!&lt;/p&gt;

&lt;p&gt;EDIT:&lt;br/&gt;
I will respect this so-called &quot;bug&quot; post once I don&apos;t see Forge ModLoader referenced.&lt;/p&gt;</comment>
                            <comment id="47322" author="unon1100" created="Sun, 24 Feb 2013 02:29:28 +0100"  >&lt;p&gt;Also, the {noformat} tags don&apos;t turn it into an IDE like environment, all it does is make it so that Tabs are actually tabs, not bullet points.&lt;/p&gt;</comment>
                            <comment id="47320" author="unon1100" created="Sun, 24 Feb 2013 02:21:07 +0100"  >&lt;p&gt;Ok fine, but this still isn&apos;t a bug. A bug is something that is broken about the game, not something that is badly implemented. This site is for bugs. In fact, you labeled it as a bug!&lt;/p&gt;</comment>
                            <comment id="47297" author="bugi74" created="Sun, 24 Feb 2013 00:12:32 +0100"  >&lt;p&gt;Not a feature request. Feature request is intended to change the functionality. This suggestion intends to improve a very bad implementation without any change to functionality.&lt;/p&gt;

&lt;p&gt;This as close to a bug one can get without it being fully one. Lets just say, one would not pass the relevant exercise in university programming course if this mistake had been done.&lt;/p&gt;

&lt;p&gt;In addition to wrapping the code inside {code}, I&apos;d add a significant missing info in the begin of the descriptions: &quot;readPacketCache is a synchronized &lt;em&gt;array&lt;/em&gt; list&quot;.&lt;/p&gt;</comment>
                            <comment id="47295" author="unon1100" created="Sun, 24 Feb 2013 00:03:18 +0100"  >&lt;p&gt;Also, this is a feature request, technically. Not a bug.&lt;/p&gt;</comment>
                            <comment id="47294" author="unon1100" created="Sun, 24 Feb 2013 00:02:45 +0100"  >&lt;p&gt;Please put the code in {noformat}&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                        <customfield id="customfield_10500" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Confirmation Status</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10300"><![CDATA[Unconfirmed]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                        <customfield id="customfield_11700" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_11600" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>0|i0c39j:</customfieldvalue>

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