Ghostty is getting automatic scrollback compression, resulting in 70 to 90% less physical memory…
@mitchellh245K followers
167,996 views
44 Comments
Comments from the original post on X (Twitter)

@behdadesfahbod
vte / gnome-terminal have been doing gzip compression on the scrollback for decades. :)
32 likes

@mitchellh
Good to know! Thank you.
10 likes

@pmarreck
Assuming that the content of the history is more or less consistent, do you think you could get even more compression “for free” by training a zstd dictionary on the first N lines of history and then using that dictionary for the next N*M lines? (Tuning N and M up to you)
19 likes

@mitchellh
Yes absolutely. I actually tried this and got up to 95% compression. But libghostty-vt has a no C dependency policy, so we're going with something we can hand-maintain first.
50 likes

@pmarreck
inb4 I pilot an LLM-driven port of zstd to Zig 😆… I’ve already wrapped it for my zig stuff, but obviously that’s still C. I’d do it fully if I had the time
1 like

@ocornut
Kudos, I love that you are you are being careful not wasting memory while managing data that's already relatively small. (vs practically any Electron apps using 900 MB after I opened it for 30 seconds to send two messages).
9 likes

@xeophon
i absolutely love how you find all these tiny things and then go down an insane rabbit hole
7 likes

@tonksthebear
PageList also made my lossless binary snapshots much easier for syncing state between clients. Excited to see how portable this work is for the WASM version so that my remote clients can get some memory savings as well
7 likes

@mitchellh
Yep, thats part of the design is that we can encode the memory directly and transfer and its accurate. We aren't leveraging that, sounds like you are :) but we will!
7 likes

@tonksthebear
Nice, ya it was extremely helpful for my multiplexer + remote clients. Thinking out loud, I wonder if your secret multiplexer is what will push state transfer into libghostty 👀

@tchon
This is an excellent technical post. Is there a draft chnageset we can view of the new scroll back compression? Thanks for doing this.
3 likes

@rsms
Neat hack!
3 likes

@rabizzzy
you’re spoiling us 🥹
3 likes

@ignaziodes
The part I'd want to see benchmarked is fault latency on the first scroll after a long idle period, since you're going from zero resident pages to decompressing potentially tens of MB synchronously. Did that end up being imperceptible or did you have to tune the compression algorithm for fast decompress over ratio?
1 like

@mitchellh
Yeah I benchmarked this heavily and had to tune the compression as you said. Our decompression speeds are something like 10 GB/s and a page is roughly 400 KB so it decompresses more than fast enough so we don’t even skip a frame. (Note all the compressed pages are in memory still too so disk isn’t a problem yet)
1 like

@ignaziodes
10 GB/s on 400KB pages - that's tight. Keeping decompression that fast while compressing well is the real tuning challenge.

@Alberto8793
Lol I did not know I could be excited about a TUI. Nonetheless, here we are.
1 like

@TylerCLaprade
This is awesome, thank you!
1 like

@juanmaocn
blinking cursor... Now I know @mitchellh is probably really not caring the battery life.
1 like

@mitchellh
Oooooh I’m actually working on something around this. :) (Moving to a CPU timer plus CPU rendering while on battery for the cursor blink). Should be basically idle. We already drop our framerate down on idle battery though
6 likes






















