Skip to content

perf(logger): replace serde_json::json! with zero-allocation write! in logger#1042

Merged
litianningdatadog merged 1 commit intomainfrom
tianning.li/v93-degradation-investigation
Feb 24, 2026
Merged

perf(logger): replace serde_json::json! with zero-allocation write! in logger#1042
litianningdatadog merged 1 commit intomainfrom
tianning.li/v93-degradation-investigation

Conversation

@litianningdatadog
Copy link
Contributor

@litianningdatadog litianningdatadog commented Feb 24, 2026

Summary

Root cause: commit 3b533a0 introduced serde_json::json!() for JSON formatting, adding per-call heap pressure and a new crate dependency that contributes to Lambda init duration regression

JIRA: https://datadoghq.atlassian.net/browse/SVLS-8619

  • Replaces serde_json::json!() in logger.rs with direct write!/writeln! calls to the tracing Writer, eliminating two heap allocations (a Map + Value) per log call
  • Adds a write_json_escaped helper that handles all 6 mandatory JSON escape sequences inline (", \, \n, \r, \t, U+0000–U+001F)
  • Removes the "json" feature from tracing-subscriber, dropping tracing-serde as a transitive dependency and reducing binary size
  • The JSON output format is identical — no observable behavior change

Test plan

  • unit tests
  • self-monitoring tests

@litianningdatadog litianningdatadog requested a review from a team as a code owner February 24, 2026 15:37
…n logger

Commit 3b533a0 introduced serde_json::json!() for JSON log formatting,
which allocates a heap Map+Value on every log call and pulled in the
tracing-serde crate via the "json" feature of tracing-subscriber,
increasing binary size and Lambda init duration.

Replace with direct write!/writeln! calls to the tracing Writer plus a
small write_json_escaped helper that handles all 6 mandatory JSON escape
sequences inline. The output format is identical.

Also remove the "json" feature from tracing-subscriber, dropping
tracing-serde as a transitive dependency.

JIRA: https://datadoghq.atlassian.net/browse/SVLS-8619
@litianningdatadog litianningdatadog force-pushed the tianning.li/v93-degradation-investigation branch from e2c1878 to a783c82 Compare February 24, 2026 16:06
@litianningdatadog litianningdatadog merged commit bfade6e into main Feb 24, 2026
49 of 50 checks passed
@litianningdatadog litianningdatadog deleted the tianning.li/v93-degradation-investigation branch February 24, 2026 20:46
@litianningdatadog litianningdatadog restored the tianning.li/v93-degradation-investigation branch February 24, 2026 22:28
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.

2 participants