apple / swift-log

A Logging API for Swift
https://apple.github.io/swift-log/
Apache License 2.0
3.48k stars 284 forks source link

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

Closed weissi closed 3 months ago

weissi commented 4 months ago

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.

ayushi2103 commented 4 months ago

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

weissi commented 4 months ago

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!