szn

Bug 305 — isPaneValid is O(NMP) called on every PTY event

305. isPaneValid traverses all sessions/windows/panes on every PTY poll event

File: src/server/server.zig:506, 628-636, 657 Severity: LOW Status: ✅ FIXED

fn isPaneValid(self: *Server, pane: *Pane) bool {
    for (self.sessions.items) |session| {
        for (session.windows.items) |win| {
            for (win.panes.items) |p| {
                if (p == pane) return true;
            }
        }
    }
    return false;
}

Called:

With 1 session, 3 windows, 6 panes that is 18 comparisons per PTY event. PTY events are frequent (every character the child writes). This is called on every single PTY read event.

Fix: Add a valid: bool field to Pane that is set to false when the pane is destroyed. isPaneValid becomes a single boolean check. The field is set in destroyPane and killWindow.