Repository navigation
terminal: speed up formatting anywhere from ~1.5x to ~8x - #13587
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR speeds up our formatting (plain text, html, and VT) by anywhere from ~1.5x to ~8x.
The formatter is the hot path behind multiple features in Ghostty GUI: clipboard copy (plain/VT/HTML),
write_screen_file,selectionString, and terminal search sliding window. It's also the hot path for libghostty users, namely people like zmx which utilize the VT formatter to restore a terminal.This PR also adds the benchmarking infrastructure for the formatter.
How
Stylecopy +eqlwhen it matches.std.fmtwhere possible and assemble integers, RGB colors, codepoints in fixed-width buffers with a single memcpy. This was extracted partially tofastprint.zigso we can reuse it.Discardingwriter to count bytes) for pin maps. Now I'm smarter about it and do a single pass.Performance
All on my machine, 80x24 terminal, 10K lines of scrollback.
Workloads:
plainis ASCII linesunicodeis 2/3/4-byte codepoints with 10% grapheme clustersstyledis heavy SGR churnmixedis styles + Unicode + hyperlinkswrappedis a continuous soft-wrapped streampin-map/active screenare the selectionString/search-style and visible-screen-only cases respectively.