Skip to content

Write each rendered source line as one output operation - #3993

Open
Matei02355 wants to merge 2 commits into
sharkdp:masterfrom
Matei02355:buffer-rendered-lines-1147-20260907
Open

Write each rendered source line as one output operation#3993
Matei02355 wants to merge 2 commits into
sharkdp:masterfrom
Matei02355:buffer-rendered-lines-1147-20260907

Conversation

@Matei02355

Copy link
Copy Markdown
Contributor

Colored Git logs produce many output writes for ANSI segments and sidebar cells, adding overhead when bat feeds a pager.

Render each source line into a reusable string and submit it as one output operation. Preserve byte-for-byte formatting, short-write handling, I/O errors and per-line streaming. Release buffers larger than 64 KiB after their line. Unbuffered mode still submits each available input fragment; it does not wait for the next source line.

Add regression coverage for write counts across character, word and unwrapped output, short writers and broken pipes. Include a standalone benchmark that compares identically built release binaries through a draining pager and verifies output hashes before alternating timed runs.

Validation: all 476 all-feature tests passed (7 ignored), including the three new regressions. Clippy with warnings denied, formatting, whitespace checks and the library-only build passed. Baseline and candidate both emitted a complete line and subsequent partial input before stdin EOF.

On this Linux host, eight alternating runs of an 80,000-line colored log through a cat pager improved from a 1.862 s median to 0.920 s (2.02x). One million numbered lines improved from 3.604 s to 2.503 s (1.44x). Rust highlighting was approximately unchanged (1.077 s versus 1.031 s). The unchanged plain-output path varied from 36.5 ms to 39.0 ms. All four output hashes matched. These measure formatting and pipe overhead, not terminal-emulator performance; no Windows speed claim is made.

Fixes #1147.

@Matei02355
Matei02355 marked this pull request as ready for review September 7, 2026 17:36
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.

bat slow when doing a git lg and using it as the pager compared to less

1 participant