Post

We can do better than line-buffered output

Chris Wellons describes buffering terminal output by a short time deadline rather than flushing each line: programs doing lots of small work can batch writes while still showing progress promptly. His tugz example checks the deadline between chunks of decompression work, avoiding a separate thread.

The caveat is that this only flushes when the program calls the deadline check: if work blocks without checking, output may remain buffered. HN readers discuss work-or-time flushing and point out that the comparison to Nagle’s algorithm is imperfect.