amanusk / amanusk/snbeat

perf(main loop): let terminal input win over response bursts and coalesce buffered key events before redrawing

未关闭
#91 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
M performance snbeat
主要语言
Rust
星标
6
派生
1
平均合并
7 分钟
30 天内合并 PR
1

描述

## Problem

`run_loop` in `src/main.rs` redraws the whole frame at the top of every iteration and then waits in an unbiased `tokio::select!` on either the crossterm `EventStream` or the network response channel.

Two consequences when background traffic is steady (new block every ~2 s, WS address events, enrichment responses, price updates):

1. When both branches are ready, `select!` picks randomly, so a pending key press loses to a response burst about half the time and waits for up to 64 `handle_action` calls plus a redraw before it is processed.
2. Every key event costs a full frame. A terminal paste arrives as one key event per character (bracketed paste is not enabled; `Event::Paste` is ignored), so pasting a 66-char address renders 66 frames and visibly appears one character at a time whenever a frame is not trivially cheap.

## Proposed fix

- Add `biased;` to the `select!` with the terminal branch first so input is always serviced before responses.
- After handling one key event, drain any already-buffered events synchronously with `crossterm::event::poll(Duration::ZERO)` + `event::read()` before redrawing (safe at that point: `EventStream`'s wake task is not outstanding right after a `Ready` poll). Same shape as the existing `MAX_DRAIN` response drain.
- Optionally enable bracketed paste (`EnableBracketedPaste`) and handle `Event::Paste` in search mode so a paste is a single event.

## Severity

Medium: the fix is small and independent, but it only matters once a frame is not negligible, so it is secondary to keeping per-frame work bounded.

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。