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

Re-specialize interpolation segment invocations on String after specializing

    XMLWordPrintable

    Details

      Description

      In https://forums.swift.org/t/performance-overhead-for-protocols/27104/6, a generic function is slower after generic specialization than the equivalent concrete function, because the generic function still uses the fully dynamic string interpolation entry point instead of one of the specific entry points. In a reduced example:

      func foo<T: FloatingPoint>(x: T) -> String { return "\(x)" }
      func bar(x: Double) -> String { return "\(x)" }
      

      bar uses the appendInterpolation<T: TextOutputStreamable> implementation, and foo uses the fully generic implementation, even if we later specialize foo for T == Double. Since we know the behavior of the fully generic appendInterpolation implementation, we could conceivably re-specialize calls into it if we later specialize a call to a type that we know statically conforms to one of the customization protocols.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              jckarter Joe Groff
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: