Page MenuHome

BLF: Save fixed_width value in cache
ClosedPublic

Authored by Harley Acheson (harley) on Nov 15 2021, 7:52 PM.

Details

Summary

Cache the font size's ideal fixed width column size in the glyph cache
rather than the font itself to improve performance.


In D12976 I removed a number of instances where we acquired GlyphCacheBLF just to get generic font metrics, which causes a thread lock. One of these items was the function blf_font_fixed_width. This function acquired cache, did searches for a sample glyph, returned that width, and released the cache.

My improvement instead calculated the width in blf_font_size and saved the value in the FontBLF. Unfortunately while drawing the interface we can do a lot of switching between font sizes, with this calculation being done every time. @Ray Molenkamp (LazyDodo) noticed this while profiling.

A seemingly easy improvement would be to only do this calculation when the font size actually changes. However, we still legitimately change between multiple sizes too often while printing.

This patch instead moves this value from the FontBLF to the GlyphCacheBLF, calculated when the cache is created for a size. This does mean that blf_font_fixed_width needs to acquire cache but at least does not have to do any glyph lookups or loading.

Diff Detail

Repository
rB Blender

Event Timeline

Harley Acheson (harley) requested review of this revision.Nov 15 2021, 7:52 PM
Harley Acheson (harley) created this revision.

Updated to the current state of master.

Updated to current state of master.

Harley Acheson (harley) edited the summary of this revision. (Show Details)

Updated to the current state of master.

This revision is now accepted and ready to land.Feb 4 2022, 2:46 AM
This revision was automatically updated to reflect the committed changes.