StringSwitch in Sema/TypeCheckAttr.cpp creates pathologically large code #76387
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
triage needed
This issue needs more specific labels
Description
Clang is having issues compiling this line of C++ code in the Swift compiler. The code in question does this:
This is just inefficient C++. There are 278 hits for FUNCTION in RuntimeFunctions.def, so this creates 1112
.Case
method calls. This generates a large CFG which is expensive for the compiler to optimize, and is ultimately not optimal code, it is notionally a sequence ofif (S == "asdf") return false;
.For compilation efficiency and runtime efficiency, please consider representing the list of runtime functions as data, like with a StringSet of names that you can test against.
We may consider filing an additional bug against clang if we can produce a reproducer for Clang, but I wanted to file this in Swift first because there is an opportunity to make the Swift compiler more efficient.
cc @compnerd for amusement, as the person I probably know best who works on Swift.
Reproduction
Touch the TypeCheckAttr.cpp C++ file, rebuild Swift, observe how long it takes to compile. Rebuild that file with
-ftime-trace
and observe how much time is spent compiling this StringSwitch.Expected behavior
This file should compiler faster and with smaller object code.
Environment
appears present at head
Additional information
No response
The text was updated successfully, but these errors were encountered: