typesetting icon indicating copy to clipboard operation
typesetting copied to clipboard

Question: why is the default `HarfBuzzShaper` cache size 0?

Open hajimehoshi opened this issue 7 months ago • 6 comments

Yesterday, I found that HarfBuzzShaper's cache size was 0 and NewFont was called every time different texts are rendered:

  • https://github.com/hajimehoshi/guigui/issues/64
  • https://github.com/hajimehoshi/ebiten/issues/3228

This issue could be prevented by settings some cache size. I was wondering why 0 is the initial value. Would it be possible to have initial cache size to avoid future troubles like me?

hajimehoshi avatar Apr 20 '25 04:04 hajimehoshi

I guess the reason is that we do not have a constructor for HarfBuzzShaper and the zero value for the fontLRU cache has 0 as its maxSize.

I'm not sure there is an easy fix. Perhaps a better documentation could be enough ? (cc @whereswaldon )

benoitkugler avatar Apr 25 '25 11:04 benoitkugler

I guess the reason is that we do not have a constructor for HarfBuzzShaper and the zero value for the fontLRU cache has 0 as its maxSize.

If this struct needs to have a non-zero cache by default, I'd have an integer member substracted by the default value so that the initial value (0) indicates the default value.

hajimehoshi avatar Apr 25 '25 11:04 hajimehoshi

I actually thought about it, but what would SetCacheSize do then ? It would not do what the user expects

benoitkugler avatar Apr 25 '25 14:04 benoitkugler

what would SetCacheSize do then ?

This function would update the member variable with the argument minus the default size.

hajimehoshi avatar Apr 25 '25 14:04 hajimehoshi

what would SetCacheSize do then ?

This function would update the member variable with the argument minus the default size.

Ah of course ! 😅

benoitkugler avatar Apr 25 '25 15:04 benoitkugler

I'm fine with adjusting the implementation to set a default cache size. I agree that size zero by default is a little silly.

whereswaldon avatar Apr 30 '25 13:04 whereswaldon