RFR [8011215] optimization of CopyOnWriteArrayList.addIfAbsent()

Ulf Zibis Ulf.Zibis at CoSoCo.de
Tue Apr 2 21:17:25 UTC 2013


Hi,

maybe the old code wins for looong arrays, so there could be a threshold to decide between old and 
new code:

-Ulf

Am 02.04.2013 23:11, schrieb Ivan Gerasimov:
>
>> Thanks for this change.  There is a tradeoff here.  If the element is never present, then the 
>> older code might be a little faster, because we can avoid re-traversing the array.  Otherwise, 
>> the new code is better.
>
> I've done a little testing on my side.
> I used Integer as an underlying type and set length of the array to the values from 1 to 100.
> My code shows a little performance gain - approximately 9%.
> I understand it may not be there for all cases, but at least for some cases it is there.
>
>> I prefer it your way (I hate unneeded allocation), but the code was intentionally written the 
>> other way.  Let's hear from Doug...
>>
>> Martin
>>
>>
>> On Tue, Apr 2, 2013 at 1:38 PM, Ivan Gerasimov <ivan.gerasimov at oracle.com 
>> <mailto:ivan.gerasimov at oracle.com>> wrote:
>>
>>
>>>         Please review my proposal for the
>>>         CopyOnWriteArrayList.addIfAbsent() method optimization.
>>>
>>> http://washi.ru.oracle.com/~igerasim/webrevs/8011215/webrev/index.html
>>> <http://washi.ru.oracle.com/%7Eigerasim/webrevs/8011215/webrev/index.html>
>>>
>>>
>>>     This URL is not readable by external reviewers.
>>
>>     The webrev has been copied here:
>>     http://cr.openjdk.java.net/~coffeys/webrev.8011215.ivan/
>> <http://cr.openjdk.java.net/%7Ecoffeys/webrev.8011215.ivan/>
>>
>>
>>>     The "master" version of CopyOnWriteArrayList is here:
>>> http://gee.cs.oswego.edu/cgi-bin/viewcvs.cgi/jsr166/src/main/java/util/concurrent/CopyOnWriteArrayList.java?view=markup
>>>
>>     Thanks for the link!
>>     I see that the code in the master version is identical to the one
>>     I've been working on.
>>     So the optimization still could be applied.
>>
>>     Sincerely,
>>     Ivan
>>
>>
>
>




More information about the core-libs-dev mailing list