<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 class="elementToProof" style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
>  where the generated assembly code by the JITs is checked by humans</div>
<div class="elementToProof" style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Is it? I have heard anecdotes that it is still slower than direct array usage, presumably due to the modCount tracking mechanism. Don't know if escape analysis and the resulting stack allocation in the compiled code eliminates that field.</div>
<div id="appendonsend"></div>
<div style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<hr style="display: inline-block; width: 98%;">
<div id="divRplyFwdMsg" dir="ltr"><span style="font-family: Calibri, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);"><b>From:</b> core-libs-dev <core-libs-dev-retn@openjdk.org> on behalf of Remi Forax <forax@univ-mlv.fr><br>
<b>Sent:</b> Sunday, May 11, 2025 5:16 AM<br>
<b>To:</b> 임민수 <godmlzkf1@naver.com><br>
<b>Cc:</b> core-libs-dev <core-libs-dev@openjdk.org><br>
<b>Subject:</b> Re: Unnecessary logic is added to removeFirst and removeLast of ArrayList.</span>
<div class="elementToProof"> </div>
</div>
<div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Duplicating the logic is bad in some cases and not that bad in other cases.</div>
<div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Here ArrayList is one of the most used class in Java (with String and HashMap), it is heavily optimized (to the point where the generated assembly code by the JITs is checked by humans), so duplicating the logic is not a bad idea,</div>
<div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
From a documentation POV, you do not have to jump through many methods if you want to see the implementation and in terms of performance, you want the inlining to be done by hand because the methods of ArrayList are usually deep in the call graph, so you may
 reach the inlining threshold right inside removeFirst().</div>
<div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
In general, you do not optimize applications and libraries the same way.</div>
<div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Usually, you do not optimize application code that often but for a library, if a lot of people are using it, it may worth to spend time to optimize for the benefit of everybody.</div>
<div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
regards,</div>
<div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Rémi</div>
<div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
</body>
</html>