apple / swift-log

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

feat: Implement Copy-On-Write (CoW) behavior for Logger struct #297

Closed ayushi2103 closed 5 months ago

ayushi2103 commented 5 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.

ayushi2103 commented 5 months ago

In which file should I add the unit test?

FranzBusch commented 5 months ago

@swift-server-bot test this please

FranzBusch commented 5 months ago

@ayushi2103 Can you update this PR since we just landed #299 which drops support for old Swift versions. This should mean you no longer have to add the conditional conformance.