Introduce til::generational - a struct comparison helper (#15088)

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.
This commit is contained in:
Leonard Hecker
2023-04-04 15:47:36 +02:00
committed by GitHub
parent 17cf44fa71
commit 5de1fd9a7b
6 changed files with 135 additions and 3 deletions

View File

@@ -105,4 +105,11 @@
<Item Name="[ptr]">_ptr</Item>
</Expand>
</Type>
<Type Name="til::generational&lt;*&gt;">
<DisplayString>{{ gen={_generation._value}, {_value} }}</DisplayString>
<Expand>
<ExpandedItem>_value</ExpandedItem>
</Expand>
</Type>
</AutoVisualizer>