You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf(mux): BackendRegistry::id_for allocates an Rc<str> on every backend dial #1564
intern already reuses the slot of a backend the session dialled before, but Rc::from(&str) copies Backend::backend_id into a fresh Rc<str> each time. It is reached from RegistryDialer::dial, i.e. once per backend connection opened by a mux session (H1 and H2 alike).
Cost per dial
One heap allocation of 16 + backend_id.len() bytes (the RcBox header plus the string bytes), one memcpy of the id, and the matching free when the BackendId drops. The id never changes for the life of a registry entry, so the copy carries no information the Backend does not already hold.
Measurement
A counting global allocator (the model already used by lib/tests/backend_selection.rs) around repeated id_for calls on the same, already-interned backend: every call costs exactly one allocation in steady state. The PR adds that test and shows it red before the fix.
Proposed correction
Allocate the Rc<str> once, on the control plane, and make the dial path a reference-count increment:
preferred: Backend::backend_id becomes an Rc<str> built in Backend::new, and id_for clones it (zero allocations per dial);
fallback, if the type change spreads beyond a handful of call sites or into a public API of sozu-command-lib: BackendRegistry caches one Rc<str> beside each slot, so the id is allocated once per session and per backend instead of once per dial.
The PR will state which one it takes and why, and pin the steady-state allocation count with a regression test.
Activity
perf(mux): stop allocating the backend id on every backend dial
perf(mux): stop allocating the backend id on every backend dial
perf(mux): stop allocating the backend id on every backend dial (sozu…