-
Bug
-
Resolution: Fixed
-
P3
-
None
The static method Collections.addAll claims to
"""to run significantly faster under most implementations"""
but this seems dubious, since all it does it optimize away one call to Arrays.asList, but at the cost of not taking advantage of any "bulk add" optimizations made by the collection in question. Concurrent collections like ConcurrentLinkedQueue can add an entire chain of elements with a single CAS. CopyOnWriteArrayList makes a copy of the backing array on each call to add. Even for ArrayList, sublists have O(N + M) addAll while a call to add in a loop is O(N * M).
"""to run significantly faster under most implementations"""
but this seems dubious, since all it does it optimize away one call to Arrays.asList, but at the cost of not taking advantage of any "bulk add" optimizations made by the collection in question. Concurrent collections like ConcurrentLinkedQueue can add an entire chain of elements with a single CAS. CopyOnWriteArrayList makes a copy of the backing array on each call to add. Even for ArrayList, sublists have O(N + M) addAll while a call to add in a loop is O(N * M).