Re: Proposal: ArrayList constructor perforrmance improvement

2018-12-19 Thread Martin Buchholz
Thanks as always to Jason, our master Historian. On Wed, Dec 19, 2018 at 2:14 AM Steve Groeger wrote: > > Yes, the intent was to leave the backing array the same size in order to > avoid to have the resize of it when a new element is added. > So, if someone wanted to reduce the size of the backi

Re: Proposal: ArrayList constructor perforrmance improvement

2018-12-19 Thread Steve Groeger
es with number 741598. Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU From: Jason Mehrens To: Martin Buchholz , Stuart Marks Cc: core-libs Date: 19/12/2018 04:54 Subject: Re: Proposal: ArrayList constructor perforrmance improvement Sent by:

Re: Proposal: ArrayList constructor perforrmance improvement

2018-12-18 Thread Jason Mehrens
>Sorry for not having remembered the history. **Start the wavy motion effect because we are going back in time! == Date: Wed, 27 Sep 2006 16:49:47 -0700 From: Martin Buchholz Subject: 6347106 (coll) Make ArrayList(Collection) more threadsafe Sender: To: Jason Mehrens Hi Jason, Thanks for

Re: Proposal: ArrayList constructor perforrmance improvement

2018-12-18 Thread Martin Buchholz
Sorry for not having remembered the history. Having ArrayList(Collection) delegate to toArray was done for performance and robustness. We don't want to change the "trimming" behavior of collection copying, because trimming by copying is a common idiom (we never added trimming methods to all the col

Re: Proposal: ArrayList constructor perforrmance improvement

2018-12-18 Thread Stuart Marks
On 12/18/18 1:49 PM, Jason Mehrens wrote: The reason the patched code is faster is because it will avoid an array resize that is triggered in the benchmark by: "// once a new ArrayList is created add a new element al.add(new Integer(900));" http://cr.openjdk.java.net/~sgroeger/perf

Re: Proposal: ArrayList constructor perforrmance improvement

2018-12-18 Thread Stuart Marks
On 12/18/18 9:23 AM, Martin Buchholz wrote: The blessed solution to the list copy problem is probably List.copyOf https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/List.html#copyOf(java.util.Collection) which might do the optimization you're hoping for. List.copyOf is fine,

Re: Proposal: ArrayList constructor perforrmance improvement

2018-12-18 Thread Jason Mehrens
The reason the patched code is faster is because it will avoid an array resize that is triggered in the benchmark by: "// once a new ArrayList is created add a new element al.add(new Integer(900));" http://cr.openjdk.java.net/~sgroeger/perf/arraylist/ArrayListBenchmark.java If you look

Re: Proposal: ArrayList constructor perforrmance improvement

2018-12-18 Thread Scott Palmer
> On Dec 18, 2018, at 12:58 PM, Jason Mehrens wrote: > > Hi Steve, > >> ArrayList has a constructor which takes an arbitrary Collection as a >> parameter. This constructor will create an iterator over the collection >> ;and it will add each entry returned to the ArrayList. > >> We have fou

Re: Proposal: ArrayList constructor perforrmance improvement

2018-12-18 Thread Jason Mehrens
Hi Steve, >ArrayList has a constructor which takes an arbitrary Collection as a >parameter. This constructor will create an iterator over the collection >;and it will add each entry returned to the ArrayList. >We have found that quite a lot of the time the object passed as a >parameter is in

Re: Proposal: ArrayList constructor perforrmance improvement

2018-12-18 Thread Alan Bateman
On 18/12/2018 16:44, Steve Groeger wrote: Hi all, I am proposing an enhancement to ArrayList.java to improve its performance. ArrayList has a constructor which takes an arbitrary Collection as a parameter. This constructor will create an iterator over the collection and it will add each entry r

Re: Proposal: ArrayList constructor perforrmance improvement

2018-12-18 Thread Martin Buchholz
This is no question that we can optimize the case of ArrayList -> ArrayList, but what about all the other Collection implementations? ArrayDeque and CopyOnWriteArrayList come to mind. ArrayList is a popular class to use for making copies of Collections. Where do you stop? A pathological subclass

Proposal: ArrayList constructor perforrmance improvement

2018-12-18 Thread Steve Groeger
Hi all, I am proposing an enhancement to ArrayList.java to improve its performance. ArrayList has a constructor which takes an arbitrary Collection as a parameter. This constructor will create an iterator over the collection and it will add each entry returned to the ArrayList. We have foun