Skip to content

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

Merged
weissi merged 21 commits intoapple:mainfrom
ayushi2103:Logger-Copy-on-Write
May 30, 2024
Merged

feat: Implement Copy-On-Write (CoW) behavior for Logger struct#297
weissi merged 21 commits intoapple:mainfrom
ayushi2103:Logger-Copy-on-Write

Conversation

@ayushi2103
Copy link
Contributor

@ayushi2103 ayushi2103 commented May 9, 2024

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
Copy link
Contributor Author

In which file should I add the unit test?

@FranzBusch
Copy link
Member

@swift-server-bot test this please

@ayushi2103 ayushi2103 requested review from FranzBusch and weissi May 10, 2024 00:18
@ayushi2103 ayushi2103 marked this pull request as ready for review May 10, 2024 00:18
@ayushi2103 ayushi2103 requested review from FranzBusch and weissi May 11, 2024 20:59
@FranzBusch
Copy link
Member

@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.

@ayushi2103 ayushi2103 force-pushed the Logger-Copy-on-Write branch from c9174e0 to e071509 Compare May 17, 2024 11:40
ayushi2103 and others added 2 commits May 17, 2024 08:40
@ayushi2103 ayushi2103 requested review from FranzBusch and weissi May 21, 2024 13:19
@ayushi2103 ayushi2103 requested a review from FranzBusch May 22, 2024 13:31
Copy link
Member

@FranzBusch FranzBusch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me! @weissi you want to take a last look as well before we merge?

Copy link
Member

@weissi weissi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, this is almost there. Two little suggestions

@ayushi2103 ayushi2103 requested a review from weissi May 30, 2024 09:51
Copy link
Member

@weissi weissi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing! Thank you so much, this will be quite the perf boost for certain things!!

@weissi weissi merged commit 2351723 into apple:main May 30, 2024
@ayushi2103 ayushi2103 deleted the Logger-Copy-on-Write branch May 30, 2024 10:20
cgrindel-self-hosted-renovate bot referenced this pull request in cgrindel/rules_swift_package_manager Jun 27, 2024
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [apple/swift-log](https://togithub.com/apple/swift-log) | minor |
`from: "1.5.4"` -> `from: "1.6.1"` |

---

### Release Notes

<details>
<summary>apple/swift-log (apple/swift-log)</summary>

### [`v1.6.1`](https://togithub.com/apple/swift-log/releases/tag/1.6.1):
Swift Log 1.6.1

[Compare
Source](https://togithub.com/apple/swift-log/compare/1.6.0...1.6.1)

##### SemVer Patch

- Disable existential any build setting
([#&#8203;312](https://togithub.com/apple/swift-log/issues/312))

### [`v1.6.0`](https://togithub.com/apple/swift-log/releases/tag/1.6.0)

[Compare
Source](https://togithub.com/apple/swift-log/compare/1.5.4...1.6.0)

#### SemVer Minor

- Add Sendability annotations in
[https://github.com/apple/swift-log/pull/308](https://togithub.com/apple/swift-log/pull/308)
- Fix deprecation warnings around default log implementations on
handlers in
[https://github.com/apple/swift-log/pull/310](https://togithub.com/apple/swift-log/pull/310)
- Drop Swift versions earlier than 5.8 in
[https://github.com/apple/swift-log/pull/299](https://togithub.com/apple/swift-log/pull/299)
- Implement Copy-On-Write (CoW) behavior for Logger struct by
[@&#8203;ayushi2103](https://togithub.com/ayushi2103) in
[https://github.com/apple/swift-log/pull/297](https://togithub.com/apple/swift-log/pull/297)

##### SemVer Patch

- Replace standardOutput to standardError by
[@&#8203;ayushi2103](https://togithub.com/ayushi2103) in
[https://github.com/apple/swift-log/pull/295](https://togithub.com/apple/swift-log/pull/295)
- Use Set to spot duplicated log handler warnings in
[https://github.com/apple/swift-log/pull/306](https://togithub.com/apple/swift-log/pull/306)
- Make protocol usage obvious using any and some keywords in
[https://github.com/apple/swift-log/pull/307](https://togithub.com/apple/swift-log/pull/307)
- Remove documentation for non-existent arguments by
[@&#8203;b1ackturtle](https://togithub.com/b1ackturtle) in
[https://github.com/apple/swift-log/pull/309](https://togithub.com/apple/swift-log/pull/309)
- Remove Docc plugin which is no longer required in
[https://github.com/apple/swift-log/pull/311](https://togithub.com/apple/swift-log/pull/311)

##### Other Changes

- Remove archived repository in
[https://github.com/apple/swift-log/pull/292](https://togithub.com/apple/swift-log/pull/292)
- Add CI for Swift 5.10 in
[https://github.com/apple/swift-log/pull/287](https://togithub.com/apple/swift-log/pull/287)
- Added swift-log-ecs to README.md by
[@&#8203;rwbutler](https://togithub.com/rwbutler) in
[https://github.com/apple/swift-log/pull/298](https://togithub.com/apple/swift-log/pull/298)
- Update README.md add shipbook as backend by
[@&#8203;elishas](https://togithub.com/elishas) in
[https://github.com/apple/swift-log/pull/304](https://togithub.com/apple/swift-log/pull/304)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get
[config help](https://togithub.com/renovatebot/renovate/discussions) if
that's undesired.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://togithub.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi4xMDkuNCIsInVwZGF0ZWRJblZlciI6IjM2LjEwOS40IiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: Self-hosted Renovate Bot <361546+cgrindel-self-hosted-renovate[bot]@users.noreply.github.enterprise.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants