Optimization of font kerning by only caching kerning values after a
pair is encountered. Also saves unscaled values so they don't have to
be rebuilt between font size changes.
We cache kerning values for ASCII characters, but we do so in a very inefficient manner. We do so in units that are specific to the current font size, which means the cache is invalidated when the font size changes. And we change font sizes constantly while drawing the UI. And whenever it becomes invalidated we preload the cache by interrogating the font for all possible character combinations. This is more than 16,000 function calls. And we do this very very often as we print with size 12 then size 11 then 12 again...
This patch saves the kerning values in design amounts that are unscaled. This means a single kerning cache table can be used for all font sizes. We just create it once when we load the font and then use it throughout all uses without having to recreate it. This means that if we encounter "Te" in one font size we will already have it cached when we see the same two letters in a different size.
This patch also makes it so that kerning values are only cached after kerning pairs are encountered. So we never waste time caching values that are never used.
Performance Comparison
On my old machine, with scale set to 1 and thumbnail size set to "tiny". I can delete my local thumbnail cache, open File Browser fullscreen in my fonts folder. It creates 350 font previews, each with "The quick brown fox.." so using a nice portion of the alphabet.
In 2.93 this takes 20.4 seconds. With this patch (and the other changes before it) this take about half a second.