Skip to content

perf(logger/sink): drop per-log String clone (#189)#241

Closed
SAY-5 wants to merge 2 commits intoTrueNine:devfrom
SAY-5:perf/sink-no-string-clone-189
Closed

perf(logger/sink): drop per-log String clone (#189)#241
SAY-5 wants to merge 2 commits intoTrueNine:devfrom
SAY-5:perf/sink-no-string-clone-189

Conversation

@SAY-5
Copy link
Copy Markdown
Contributor

@SAY-5 SAY-5 commented Apr 29, 2026

Closes #189.

send_output cloned the formatted string for the channel send and kept the original around only for the rare sink-thread-dead fallback. On the hot path (sink alive), every write_event / write_span_* paid a String::clone for nothing.

Move the String straight into the channel. mpsc::SendError already hands the unsent value back on the disconnect path, so we can pull it out via if let Err(SendError(OutputCommand::Write { output, .. })) and borrow it directly into write_direct. No allocation on the happy path; the cold path is unchanged.

Test plan

  • cargo build --manifest-path sdk/Cargo.toml — clean
  • cargo test --manifest-path sdk/Cargo.toml --lib infra::logger — 16/16 pass (including test_thread_safety)
  • cargo clippy --manifest-path sdk/Cargo.toml --lib — no new warnings on sink.rs (pre-existing warnings on other modules unchanged)

TrueNine and others added 2 commits April 25, 2026 10:10
Fix two CI failures from previous merge
Closes TrueNine#189.

`send_output` cloned the formatted string for the channel send and
kept the original around only for the rare sink-thread-dead fallback.
On the hot path (sink alive), every `write_event` / `write_span_*`
paid a `String::clone` for nothing.

Move the `String` straight into the channel. `mpsc::SendError` already
hands the unsent value back on the disconnect path, so we can pull it
out via `if let Err(SendError(OutputCommand::Write { output, .. }))`
and borrow it directly into `write_direct`. No allocation on the
happy path; the cold path is unchanged.

`cargo build --manifest-path sdk/Cargo.toml` clean. The 16 logger
unit tests pass, including `test_thread_safety`. `cargo clippy
--lib` shows no new warnings against `sink.rs` (the existing
warnings on other modules are unchanged).
@SAY-5 SAY-5 requested a review from TrueNine as a code owner April 29, 2026 21:45
@TrueNine TrueNine changed the base branch from main to dev April 30, 2026 08:08
@TrueNine
Copy link
Copy Markdown
Owner

Merged into dev via cherry-pick. The PR base was changed from main to dev, which caused conflicts because dev had diverged significantly. All commits have been cherry-picked onto dev and pushed. Thanks for the contributions!

@TrueNine TrueNine closed this Apr 30, 2026
@TrueNine
Copy link
Copy Markdown
Owner

Thank you for the contribution! All commits have been cherry-picked and merged into the dev branch. 🙏

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.

[Logger/Sink] 每次日志输出都做不必要的 String clone

2 participants