I currently truncate buffers at 20,000 lines by adding the following to my configuration:
(setq eshell-buffer-maximum-lines 20000)
;; automatically truncate buffer after output
(add-to-list 'eshell-output-filter-functions 'eshell-truncate-buffer)
This works great for < 20,000 lines, and once the buffer reaches 20,000 lines it gets truncated on every line (so it sits at 20,001 lines forever). However, when the buffer reaches 20,000 lines, each subsequent line takes much longer to be printed and causes the CPU of emacs to sit at 100% for quite a while.
Is there a way to improve the performance of the buffer truncation? Perhaps only truncating every 100 added lines? It's not like I really need it to be exactly 20,000 lines, I just don't want the buffer to grow infinitely.
eshell-truncate-buffer
each each time output is produced. It may make more sense to make truncation independent on producing output. As @PythonNut suggests truncating after timeout seems more reasonable.