# Line buffering is a bottleneck — and we can do better

Original title: We can do better than line-buffered output

> Hacker News story 50380268 · language: en · submitted 2026-11-05
> Web version: https://zeli.app/story/50380268
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 111 · by [zdw](<https://news.ycombinator.com/user?id=zdw>) · 💬 13
[original](<https://nullprogram.com/blog/2026/11/05/>) · [HN discussion](<https://news.ycombinator.com/item?id=50380268>)

## Summary

Line buffering flushes on every newline, which makes programs like unzip crawl when printing many files to a terminal. The author proposes a deadline-based flush: hold output briefly (around 100ms) and send it in batches, poked between short stints of work rather than by a thread. The result looks instant to humans while running at fully buffered speed, as implemented in his tugz unzip.

## Key quote

> We can have our cake and eat it, too: promptly delivering lines to a terminal at fully-buffered speeds.

## HN discussion (13 comments)

### [Veserv](<https://news.ycombinator.com/item?id=50382808>)

> Yes, basically all buffering should use work-or-time based flushing.
>
> Work-based flushing exists to batch work to amortize overhead. It allows you to tune how much time you spend in overhead in a work period. However, this can result in unbounded delay.
>
> Time-based flushing targets a worst-case latency in low throughput environments. This ensures you do not get unbounded delays. Interestingly, this also allows you to tune how much time you spend in overhead in a work period.
>
> So, with work-or-time based flushing what you are really tuning is how much time you are willing to spend in overhead in a work period and balancing that against latency.
>
> As a nit, the article calls this a derivative of Nagle’s algorithm, but it is basically the opposite. Nagle’s algorithm is about batching until acknowledgement with no mention of time. In fact, the lack of time-based flushing in Nagle’s algorithm is why it interacts so poorly with TCP Delayed Ack.

### [chuliomartinez](<https://news.ycombinator.com/item?id=50385200>)

> I have seen versions of this many times in my life. Unfortunately, that progress report can hurt a lot, is something we devs often miss.
>
> From my horror cabinet:
>
> 1. Running count * on all sqlite tables 4x per second to show sync progress.
>
> 2. Progress bounce animation eating 80% of cpu (windows phone bizarro silverlight)
>
> 3. Sending myself 800 emails in 10 minutes…
>
> The rule is quite simple, we are just bad at it. Computer to human communication should run at human speed.

### [abecedarius](<https://news.ycombinator.com/item?id=50382462>)

> \> flush the buffer if it’s been idle a short time
>
> I've thought this was the right default for a good while. 50 years ago when Unix was designed, maybe not.

---

## Cite

- Page: https://zeli.app/story/50380268
- Date: 2026-11-05
- Source: nullprogram.com (https://nullprogram.com/blog/2026/11/05/)
- Hacker News: https://news.ycombinator.com/item?id=50380268

## Other languages

- zh: https://zeli.app/zh/story/50380268 · markdown: https://zeli.app/zh/story/50380268.md
- ja: https://zeli.app/ja/story/50380268 · markdown: https://zeli.app/ja/story/50380268.md
- ko: https://zeli.app/ko/story/50380268 · markdown: https://zeli.app/ko/story/50380268.md
- de: https://zeli.app/de/story/50380268 · markdown: https://zeli.app/de/story/50380268.md
- es: https://zeli.app/es/story/50380268 · markdown: https://zeli.app/es/story/50380268.md
- ru: https://zeli.app/ru/story/50380268 · markdown: https://zeli.app/ru/story/50380268.md
