Skip to content

[SR-3074] When call direct call of generic function is 30x slower than indirect call #45664

Open
@krzyzanowskim

Description

@krzyzanowskim
Previous ID SR-3074
Radar None
Original Reporter @krzyzanowskim
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash, Performance
Assignee None
Priority Medium

md5: 37a90ca57b69b7234d6a6ac8081ade13

Issue Description:

I have this generic function

public func update<T: Sequence>(withBytes bytes: T) throws -> Array<UInt8> where T.Iterator.Element == UInt8 {
//...
}

when called directly it's slow

Foo().update(withBytes: [1,2,3])

when called indirectly, it's fast

func helper(bytes: Array<UInt8>) {
    Foo().update(withBytes: bytes)
}

helper(bytes: [1,2,3])

when tried add

@_specialize(Array<UInt8>) to "update()", swiftc crash.

0 swift 0x0000000108912a3d PrintStackTraceSignalHandler(void*) + 45
1 swift 0x0000000108912466 SignalHandler(int) + 470
2 libsystem_platform.dylib 0x00007fff808da52a _sigtramp + 26
3 libsystem_platform.dylib 0x00007febcdbb2308 _sigtramp + 1294827000
4 swift 0x0000000105ff828d swift::SILPassManager::runOneIteration() + 8749
5 swift 0x0000000105ffc776 swift::runSILOptimizationPasses(swift::SILModule&) + 3462
6 swift 0x0000000105cbfe15 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*) + 20117
7 swift 0x0000000105cb8f70 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 17856
8 swift 0x0000000105c7593e main + 8302
9 libdyld.dylib 0x00007fff885375ad start + 1
10 libdyld.dylib 0x00000000000000fc start + 2007796560

Stack dump:
0. Program arguments: .....

  1. While running pass Remove unnecessary unsafeUnwrap calls. #2 SILModuleTransform "Eager Specializer".

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwareperformance

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions