Skip to content

perf(ffi): filter discarded Python logs before forwarding - #1647

Draft
theomonnom wants to merge 1 commit into
mainfrom
codex/python-native-log-filter
Draft

theomonnom wants to merge 1 commit into
mainfrom
codex/python-native-log-filter

Conversation

@theomonnom

@theomonnom theomonnom commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

TL;DR: Skip native log records that Python would discard before paying their allocation, serialization, and forwarding costs.

  • CPU impact: Inconclusive in the isolated control: mean CPU reduction 0.35%, with paired results +1.31% and −0.58% (positive means less CPU). The interval crosses zero.
  • More voice sessions per core/machine: No reliable increase demonstrated; do not budget extra sessions from this PR. The small mean cannot support a useful capacity claim.

FFI/protobuf scope: This removes some discarded logging work before serialization and the Python callback. It does not change the audio protobuf protocol, and the experiment does not isolate protobuf's CPU cost.


Python currently discards some native log records after Rust has allocated, serialized, and forwarded them. Apply the same policy in the native logger before that work when the FFI client identifies itself as Python.

TRACE remains discarded. DEBUG from libwebrtc and targets beginning with livekit is forwarded only when LIVEKIT_RTC_DEBUG is true or 1, with the same whitespace/case handling as Python. The environment is read dynamically. INFO/WARN/ERROR, other DEBUG targets, other SDKs, and the uncaptured env_logger path keep their existing behavior.

Validation: the Rust policy test passed for target/severity/debug combinations; cargo formatting and patch checks passed. Two controlled AgentSession trials also passed receive/loop/playout/interrupt gates. Both cohorts used the same native binary and Python callback; the early-filter flag was changed only after joining so connection metadata was identical.

The isolated CPU result is inconclusive: paired changes were +1.31% and -0.58% (mean 0.35%). No reliable session-capacity gain is claimed. Keep this optional and review it independently from the receive and Opus changes. The policy mirrors the current Python implementation and should be kept synchronized if that policy changes.

Related draft PRs: receive batching, Opus AVX2, inline VAD, RTC regression tests.

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Changeset ✓

This PR includes a changeset covering all affected packages:

Package Bump
livekit-ffi patch

This branch has not been deployed

No deployments
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.

1 participant