Files
synapse/rust
Erik JohnstonandClaude Fable 5 780d20883d Avoid per-switch and per-log-record allocations in the logcontext hot path
Two allocation classes the Rust port introduced over the old Python class:

- start_inner/stop_inner (run on every context switch) and
  __enter__/__exit__ cloned the context-name String up front, though it is
  only needed in the misuse-error branches and the opt-in debug traces.
  Materialise it in those branches instead, and guard __enter__'s debug
  trace with log_enabled! as __exit__ already did, keeping the switch fast
  path allocation-free.

- name/server_name were stored as Rust Strings, so every Python read built
  a fresh str — and LoggingContextFilter reads server_name plus
  str(context) on every log record process-wide. Store them (and the
  sentinel's counterparts) as Py<PyString> so getters and __str__ return
  the stored object INCREF-only, matching the old Python class.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JFbRtswu7rsHrttJFauUUb
2026-07-16 15:06:57 +00:00
..