While profiling my code, I've found a lot of calls to "outlined init with take" functions that are surprisingly expensive.
These calls really add up - for instance, the function shown writes a normalized URL string, including percent-encoding inputs, parsing and rewriting a path, etc, and instruments shows this one line amounts to around 8% of the time spent in the function (recorded in high frequency mode):
And that's just one function.
Now, info.schemeKind
is a stored property of type Optional<WebURL.SchemeKind>
, and WebURL.SchemeKind
is an enum with 7 cases. I would expect Optional<WebURL.SchemeKind>
to occupy exactly 1 byte, and printing MemoryLayout<Optional<WebURL.SchemeKind>>.size
confirms that. Copying a single byte which is a stored property shouldn't require runtime calls.
I've seen this with other small enums, as well. I have a Sigil
enum with only 2 cases, and I'm seeing the same expensive "init with take" functions all around my code.
I can't understand what's causing this - does anybody have any information? How can I avoid them?