apple/swift-log

CoW (copy-on-write) box the `Logger` components (for perf)

Closed this issue · 2 comments

Since literally before day 0 we planned for the components in Logger to be CoW-boxed to improve performance passing around a Logger. Logger needs to hold an existential (5 words & ARC! LogHandler) and is much more frequently passed around than created.

There should be an enormous performance benefit if we CoW-boxed the Logger. The work should be really straightforward.


Today, Logger is

public struct Logger {
    var handler: LogHandler
    let label: String
}

LogHandler is an existential so this is 5 words, String is 2 words. So in almost all cases in the best case we need to copy 7 words(!) and do two ARCs. If LogHandler is a struct which has a bunch of other ref-counted members this could be worse.

With a CoW box this will come down to 1 word & 1 ARC retain/release but of course an extra level of indirection when logging. That however shouldn't matter too much.

Hi @weissi, can this be assigned to me, I have a draft PR out for the issue.

Hi @weissi, can this be assigned to me, I have a draft PR out for the issue.

amazing, thank you, we really appreciate your work on this!