<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Hello Eirik, this is a general problem caused by type profile pollution in bytecode of these constructors so that virtual calls become slow, fully virtual calls. I do not think this site is used frequent enough that warrants a monkey patch like that in ArrayList;
 such monkey patches will be removed in the future shall the JVM provide a better specialization solution.</div>
<div style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<br>
</div>
<div style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
If you want to learn more about how type profile pollution works, feel free to check out the patch for <a href="https://bugs.openjdk.org/browse/JDK-8366424">https://bugs.openjdk.org/browse/JDK-8366424</a>, where there's a benchmark that explains how all these
 pollutions happen.</div>
<div style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<br>
</div>
<div style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Regards,</div>
<div style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Chen Liang</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> core-libs-dev <core-libs-dev-retn@openjdk.org> on behalf of Eirik Bjørsnøs <eirbjo@gmail.com><br>
<b>Sent:</b> Wednesday, February 25, 2026 9:08 AM<br>
<b>To:</b> core-libs-dev <core-libs-dev@openjdk.org><br>
<b>Subject:</b> [External] : RFD: Specializing ArrayDeque copy constructor for ArrayDeque (and possibly ArrayList)</font>
<div> </div>
</div>
<style>
<!--
#x_pfptBannery4rtrfa
        {display:block!important;
        visibility:visible!important;
        opacity:1!important;
        background-color:#60beeb!important;
        max-width:none!important;
        max-height:none!important}
html:root, html:root > div
        {display:block!important;
        visibility:visible!important;
        opacity:1!important}
-->
</style>
<div>
<div style="display:none!important; display:none; visibility:hidden; font-size:1px; color:#ffffff; line-height:1px; max-height:0px; opacity:0; overflow:hidden">
Hi, While looking into ArrayDeque: : addElements recently, I noticed that the copy constructor ArrayDeque(Collection) does not specialize for an ArrayDeque being passed in a similar fashion to what ArrayList does. By utilizing the ArrayListBulkOpsBenchmark</div>
<div style="display:none!important; display:none; visibility:hidden; font-size:1px; color:#ffffff; line-height:1px; max-height:0px; opacity:0; overflow:hidden">
ZjQcmQRYFpfptBannerStart</div>
<div dir="ltr" lang="en" id="x_pfptBannery4rtrfa" style="display:block!important; text-align:left!important; margin:0 0 10px 0!important; padding:7px 16px 8px 16px!important; border-radius:4px!important; min-width:200px!important; background-color:#60beeb!important; background-color:#60beeb; border-top:4px solid #8193a0!important; border-top:4px solid #8193a0">
<div id="x_pfptBannery4rtrfa" style="float:left!important; display:block!important; margin:1px 0 1px 0!important; max-width:600px!important">
<div id="x_pfptBannery4rtrfa" style="display:block!important; visibility:visible!important; background-color:#60beeb!important; color:#000000!important; color:#000000; font-family:'Arial',sans-serif!important; font-family:'Arial',sans-serif; font-weight:bold!important; font-weight:bold; font-size:14px!important; line-height:1.29!important; line-height:1.29">
This Message Is From an External Sender </div>
<div id="x_pfptBannery4rtrfa" style="display:block!important; visibility:visible!important; background-color:#60beeb!important; color:#000000!important; color:#000000; font-weight:normal; font-family:'Arial',sans-serif!important; font-family:'Arial',sans-serif; font-size:12px!important; line-height:1.5!important; line-height:1.5; margin-top:2px!important">
This message came from outside your organization. </div>
</div>
<div id="x_pfptBannery4rtrfa" style="float:right!important; display:block!important; display:block; margin-left:16px!important; margin-top:1px!important; text-align:right!important; width:fit-content!important; font-size:12px!important">
<a id="x_pfptBannery4rtrfa" href="https://us-phishalarm-ewt.proofpoint.com/EWT/v1/ACWV5N9M2RV99hQ!Op20OCpm1CSlHTAAv166s1TUpoWxmKY80Fp0sfkRpwj3IiVbBFywyh2YCoQcpFBR61255FrMKi3x_VMgCQbiIMhr3epTsIh7u6f_8RvkbTHciw10cvaXUBuMqLQ0-59vRQ$" style="display:inline-block!important; text-decoration:none">
<div class="x_pfptPrimaryButtony4rtrfa" style="display:inline-block!important; display:inline-block; visibility:visible!important; opacity:1!important; color:#000000!important; color:#000000; font-family:'Arial',sans-serif!important; font-family:'Arial',sans-serif; font-size:14px!important; font-weight:normal!important; text-decoration:none!important; border-radius:2px!important; margin-top:3px!important; margin-bottom:3px!important; margin-left:16px!important; padding:7.5px 16px!important; white-space:nowrap!important; width:fit-content!important; border:1px solid #666666">
Report Suspicious </div>
</a></div>
<div style="clear:both!important; display:block!important; visibility:hidden!important; line-height:0!important; font-size:0.01px!important; height:0px">
 </div>
</div>
<div style="display:none!important; display:none; visibility:hidden; font-size:1px; color:#ffffff; line-height:1px; max-height:0px; opacity:0; overflow:hidden">
ZjQcmQRYFpfptBannerEnd</div>
<div dir="ltr">Hi,
<div><br>
</div>
<div>While looking into ArrayDeque::addElements recently, I noticed that the copy constructor ArrayDeque(Collection) does not specialize for an ArrayDeque being passed in a similar fashion to what ArrayList does.</div>
<div><br>
</div>
<div>By utilizing the ArrayListBulkOpsBenchmark and adopting it for ArrayDeque, I was able to test the performance impact of specializing ArrayDeque(Collection) for ArrayDeque.</div>
<div><br>
</div>
<div>Results show a reduction in time/op ranging from 30% (1 element) to 75% (75 elements).</div>
<div><br>
</div>
<div>I also experimented with a similar specialization for ArrayList which shows promising results, up to 50% faster for lists of size 75.</div>
<div><br>
</div>
<div>However, there are many collections in the JDK and which combinations to specialize for is not obvious. Is further exploration here worthwhile?</div>
<div> </div>
<div>Cheers,</div>
<div>Eirik. </div>
</div>
</div>
</body>
</html>