Uploaded image for project: 'Swift'
  1. Swift
  2. SR-877

Construction of set of strings is slow on certain strings

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: Standard Library
    • Labels:
      None
    • Environment:

      Reproduced with ToT swift.org compiler/standard library.

      Description

      Jens has reported:

      For some particular arrays of strings, creating a Set<String>(arrayOfStrings) takes about 100 to 200 times longer than for other very similar arrays of strings (equally many unique simple [a-zA-Z ]+ strings).

      I've put together a tiny program to demonstrate the problem here:
      http://sloppyfocus.com/slowSetFromParticularButSeeminglyNormalArrayOfStrings.html

      <snip>

      Just thought I should mention that I tried another thing:

      Using my original example:
      http://sloppyfocus.com/slowSetFromParticularButSeeminglyNormalArrayOfStrings.html
      Keeping the code as it is but adding a space to the end of every line in the actual text file (strings.txt).

      <snip>

      Another thing I noticed is that making a Set<NSString> (rather than a Set<String>) is fast ...

      That is (for those same particular strings) this is fast (0.7 s):
      let setOfNSStrings = Set<NSString>(strings.map

      { $0 as NSString }

      )

      while this is slow (9.5 s):
      let setOfNSStrings = Set<String>(strings)

        Attachments

          Activity

            People

            Assignee:
            aschwaighofer Arnold Schwaighofer
            Reporter:
            aschwaighofer Arnold Schwaighofer
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: