Skip to content

perf(filter): drop per-call format!("{:?}", state).to_lowercase() on SSH connection-state filter #336

@obchain

Description

@obchain

Where

src/filter.rs:388

// Check connection state
let state_str = format!("{:?}", info.connection_state).to_lowercase();
if match_text(&state_str, fv) {
    return true;
}

What

The SSH branch of matches_application_filter derives the matchable connection-state string by Debug-formatting SshConnectionState and lowercasing the result. Two heap allocations per SSH connection per filter criterion per render frame:

  1. format!("{:?}", …) builds a new String via the Debug impl.
  2. .to_lowercase() walks that string and builds another String.

Both allocations are pure waste — SshConnectionState is a fieldless 4-variant enum (Banner, KeyExchange, Authentication, Established) whose lower-case canonical form is known at compile time and can be a &'static str.

Why it matters

Filter evaluation runs over every visible SSH connection on every render tick whenever a non-empty filter query is active. The cost is small per call but cumulative — and conceptually wrong: Debug output is not a stable user-facing string and shouldn't be repurposed as a filter token.

Suggested fix

Replace the format! + to_lowercase with an exhaustive match returning &'static str. The compiler enforces sync with the enum at compile time, so future variants can't silently drift out of filter coverage.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions