swift-log icon indicating copy to clipboard operation
swift-log copied to clipboard

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

Open weissi opened this issue 2 months ago • 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.

weissi avatar Apr 29 '24 11:04 weissi

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

ayushi2103 avatar May 09 '24 12:05 ayushi2103

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!

weissi avatar May 09 '24 12:05 weissi