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

Swift subclass of NSTextStorage is slow because of Swift bridging

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Compiler, Standard Library
    • Labels:
      None
    • Environment:

      Apple Swift version 4.0 (swiftlang-900.0.65.2 clang-900.0.37)

      Target: x86_64-apple-macosx10.9

      macOS 10.13

      Description

      `NSTextStorage` vs. `TextStorageSwiftSubclass`

      Calling `-[NSTextStorage attributesAtIndex:effectiveRange:]` is nearly 3 times as slow for `TextStorageSwiftSubclass` compared to `NSTextStorage`. Time profiling shows that this is caused by the bridging of the Objective-C dictionary return value to Swift. Effectively, this means we cannot use Swift if we want to subclass `NSTextStorage`.

      Sample project and time profiler trace are attached.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              fumoboy007 Darren Mo
            • Votes:
              0 Vote for this issue
              Watchers:
              11 Start watching this issue

              Dates

              • Created:
                Updated: