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 #296

Closed ayushi2103 closed 4 months ago

ayushi2103 commented 4 months ago

Added CoW implementation for Logger struct to optimize performance and minimize memory overhead.

Motivation:

LogHandler is an existential type and has a String requiring two words so copying a Logger instance duplicates 7 words and executes two ARC operations. By implementing CoW with a boxed LogHandler, we will duplicate 1 word and one ARC operation, enhancing efficiency particularly when Logger instances are frequently passed around.

Modifications:

Added a private property _handler of type Box<LogHandler> to hold the LogHandler and updated the handler property to be computed, allowing transparent access to the LogHandler.

Result:

When the Logger instances will be passed around, the change will reduce memory overhead and potentially improve performance.