Re: Proposal: optimization of Map.copyOf and Collectors.toUnmodifiableMap

2018-06-25 Thread Stuart Marks
Hi Peter, Sorry for the delay again. I got pulled into a P1 escalation. I don't think I'll have time to look at this in any detail until after JDK 11 ramp-down. s'marks On 6/22/18 9:51 AM, Peter Levart wrote: Hi Stuart, Do you still fear that "single-threaded-object" idiom is not safe? I

Re: Proposal: optimization of Map.copyOf and Collectors.toUnmodifiableMap

2018-06-22 Thread Peter Levart
Hi Stuart, Do you still fear that "single-threaded-object" idiom is not safe? I would just like to comment on the last approach... On 06/19/2018 07:01 PM, Peter Levart wrote: Here's another attempt that uses the same technique but relaxes the possible concurrent source map scenario (where numb

Re: Proposal: optimization of Map.copyOf and Collectors.toUnmodifiableMap

2018-06-19 Thread Peter Levart
Hi Stuart, On 06/19/2018 04:09 AM, Stuart Marks wrote: On 6/17/18 4:23 PM, Peter Levart wrote: My attempt to optimize the Map.copyOf() was also using just public APIs (with the addition of an internal class). Well, it does speed-up Map.copyOf() by 30%. But I agree there are other approache

Re: Proposal: optimization of Map.copyOf and Collectors.toUnmodifiableMap

2018-06-18 Thread Stuart Marks
On 6/17/18 4:23 PM, Peter Levart wrote: My attempt to optimize the Map.copyOf() was also using just public APIs (with the addition of an internal class). Well, it does speed-up Map.copyOf() by 30%. But I agree there are other approaches that could go even further. In particular when all int

Re: Proposal: optimization of Map.copyOf and Collectors.toUnmodifiableMap

2018-06-18 Thread Stuart Marks
On 6/18/18 7:25 AM, Roger Riggs wrote: In regard to new SharedSecret interfaces, one option is move shared (but private) implementation classes to a jdk.internal.xx package (not exported).  This only works well if they are not tightly coupled to other package private classes. SpinedBuffer m

Re: Proposal: optimization of Map.copyOf and Collectors.toUnmodifiableMap

2018-06-18 Thread Roger Riggs
Hi Stuart, In regard to new SharedSecret interfaces, one option is move shared (but private) implementation classes to a jdk.internal.xx package (not exported).  This only works well if they are not tightly coupled to other package private classes. SpinedBuffer might be a good candidate, I ha

Re: Proposal: optimization of Map.copyOf and Collectors.toUnmodifiableMap

2018-06-17 Thread Peter Levart
Hi Stuart, On 06/15/18 23:22, Stuart Marks wrote: Hi Peter, Finally getting back to this. I think there's clearly room for improvement in the creation of the unmodifiable collections. Right now the creation paths (mostly) use only public APIs, which can result in unnecessary allocation and

Re: Proposal: optimization of Map.copyOf and Collectors.toUnmodifiableMap

2018-06-15 Thread Stuart Marks
Hi Peter, Finally getting back to this. I think there's clearly room for improvement in the creation of the unmodifiable collections. Right now the creation paths (mostly) use only public APIs, which can result in unnecessary allocation and copying. Certainly Map.copyOf does this, but there a

Proposal: optimization of Map.copyOf and Collectors.toUnmodifiableMap

2018-06-11 Thread Peter Levart
Hi, Those two methods were added in JDK 10 and they are not very optimal. Map.copyOf(Map map) 1st dumps the source map into an array of Map.Entry(s) (map.entrySet().toArray(new Entry[0])), which typically creates new Map.Entry objects, then passes the array to Map.ofEntries(Map.Entry[] entrie