[PR #2368] Replace CodepointWidthDetector's runtime table with a static one #24907

Open
opened 2026-01-31 09:06:02 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/2368

State: closed
Merged: Yes


This commit replaces CodepointWidthDetector's
dynamically-generated map with a static constexpr one that's compiled
into the binary.

It also almost totally removes the notion of an Invalid width. We
definitely had gaps in our character coverage where we'd report a
character as invalid, but we'd then flatten that down to Narrow when
asked. By combining the not-present state and the narrow state, we get
to save a significant chunk of data.

I've tested this by feeding it all 0x10FFFF codepoints (and then some)
and making sure they 100% match the old code's outputs.

Metric Then Now
disk space 56k (.text) 3k (.rdata)
runtime memory (allocations) 1088 0
runtime memory (bytes) 51k ~0
memory behavior not shared fully shared
lookup time ~31ns ~9ns
first hit penalty ~170000ns 0ns
lines of code 1088 285
clarity extreme slightly worse

I also took a moment and cleaned up a stray boolean that we didn't need.

**Original Pull Request:** https://github.com/microsoft/terminal/pull/2368 **State:** closed **Merged:** Yes --- This commit replaces CodepointWidthDetector's dynamically-generated map with a static constexpr one that's compiled into the binary. It also almost totally removes the notion of an `Invalid` width. We definitely had gaps in our character coverage where we'd report a character as invalid, but we'd then flatten that down to `Narrow` when asked. By combining the not-present state and the narrow state, we get to save a significant chunk of data. I've tested this by feeding it all 0x10FFFF codepoints (and then some) and making sure they 100% match the old code's outputs. | Metric | Then | Now | |------------------------------|---------------|----------------| | disk space | 56k (`.text`) | 3k (`.rdata`) | | runtime memory (allocations) | 1088 | 0 | | runtime memory (bytes) | 51k | ~0 | | memory behavior | not shared | fully shared | | lookup time | ~31ns | ~9ns | | first hit penalty | ~170000ns | 0ns | | lines of code | 1088 | 285 | | clarity | extreme | slightly worse | I also took a moment and cleaned up a stray boolean that we didn't need.
claunia added the pull-request label 2026-01-31 09:06:02 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#24907