Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8193031

Collections.addAll is likely to perform worse than Collection.addAll

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • P3
    • Resolution: Fixed
    • None
    • 17
    • core-libs

    Description

      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).

      Attachments

        Issue Links

          Activity

            People

              martin Martin Buchholz
              martin Martin Buchholz
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: