[PR #15088] Introduce til::generational - a struct comparison helper #30407

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

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

State: closed
Merged: Yes


It can be costly, difficult, or often impossible to compare two
instances of a struct. This little helper can simplify this.

The underlying idea is that changes in state occur much less often than
the amount of data that's being processed in between. As such, this
helper assumes that any modification to the struct it wraps is a
state change. When you compare the modified instance with another
the comparison operator will then always return false. This makes
state changes potentially more costly, because more state might be
invalidated than was necessary, but on the other hand it makes both,
the code simpler and the fast-path (no state change) much faster.

For instance, let's look at the amount of data that represents a
user's chosen font: It encompasses the font family, size and weight,
font axes (a vector of tuples), dpi and cell height/width overrides.
Comparing all that data, every time the user changes anything, is
fairly complex to code and maintain and costly at runtime, even though
the user will change the only font very seldomly. Instead, we can
optimize for the common case of no font changes occuring and simply
assume that if any font related field changed, all fields changed.
This is exactly what til::generational does.

**Original Pull Request:** https://github.com/microsoft/terminal/pull/15088 **State:** closed **Merged:** Yes --- It can be costly, difficult, or often impossible to compare two instances of a struct. This little helper can simplify this. The underlying idea is that changes in state occur much less often than the amount of data that's being processed in between. As such, this helper assumes that _any_ modification to the struct it wraps is a state change. When you compare the modified instance with another the comparison operator will then always return false. This makes state changes potentially more costly, because more state might be invalidated than was necessary, but on the other hand it makes both, the code simpler and the fast-path (no state change) much faster. For instance, let's look at the amount of data that represents a user's chosen font: It encompasses the font family, size and weight, font axes (a vector of tuples), dpi and cell height/width overrides. Comparing all that data, every time the user changes anything, is fairly complex to code and maintain and costly at runtime, even though the user will change the only font very seldomly. Instead, we can optimize for the common case of no font changes occuring and simply assume that if any font related field changed, all fields changed. This is exactly what `til::generational` does.
claunia added the pull-request label 2026-01-31 09:40:39 +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#30407