[concurrency-interest] RFR [8011215] optimization of CopyOnWriteArrayList.addIfAbsent()

Ivan Gerasimov ivan.gerasimov at oracle.com
Tue Apr 2 17:11:58 EDT 2013

> 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20130403/e145200f/attachment-0001.html>

More information about the Concurrency-interest mailing list