[SR-8314] Very slow compile times for static large yet simple static arrays #50842
Labels
compiler
The Swift compiler in itself
improvement
performance
type checker
Area → compiler: Semantic analysis
Attachment: Download
Additional Detail from JIRA
md5: bfd1ab26fa738a651634af78f66fe43e
Issue Description:
I've attached an SPM project which consists of a single (edited) source file, but which takes a very long time to compile, despite containing essentially one function and some static data.
In Xcode, I see a compilation time of 53.4 seconds. Using
swift build
on the terminal, it takes 40.3 seconds, with the following output fromtime -l
:...and yes, that's a 4.3GB maximum resident set. Conversely, my entire swift-nio-http2 fork build takes 14.3 seconds and uses a maximum resident set of 159MB:
The code being compiled here is a static Huffman decoding table. It consists of a long array containing 255 groups of 16 tuples, each containing three items: a UInt8, an OptionSet with a RawValue of UInt8, and another UInt8. This corresponds to the 2-dimensional C array used by nghttp2 which can be seen here.
In C, this sort of static data would be pretty easy for the compiler to handle, but here it's anything but, which seems strange. I actually remedied the issue in my swift-nio-http2 fork by getting the raw bytes of the C implementation and encoding them as a large base64 string which I copied into the code and parsed on first use. Which seems rather backwards, to be honest.
The text was updated successfully, but these errors were encountered: