It would be interesting to see a sample
, spindump
, or Instruments Time Profile of this benchmark to see where the time is being spent now. I have some guesses, but I know better than to guess about performance :)
At some point, this is just a time-space trade off. Yes, making strings take up twice as much inline memory can speed up some operations.
Most C/C++ compilers like GCC and MSVC offer optimization flags that allow choosing between optimizing for speed (-O2, -O3) or size (-Os).
Sure, but that affects things like loop unrolling, not the layout of structs. In fact the layout of Swift String
can’t be changed without breaking ABI.
The word “inline” here is subtle… some people might not be aware that in the general case, Swift strings store their characters in a heap allocation. This minimizes the cost of copying strings, but it also minimizes register pressure when passing strings as arguments. It would stink if passing a single string as an argument spilled all other arguments to the stack.