-
Notifications
You must be signed in to change notification settings - Fork 538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add caching to DrawShapedText #3033
base: main
Are you sure you want to change the base?
Conversation
/azp run |
Azure Pipelines could not run because the pipeline triggers exclude this branch/path. |
Very nice one!! Possible to avoid Maybe add a |
a12cfea
to
32fb1e3
Compare
Is it possible to use https://learn.microsoft.com/dotnet/api/system.runtime.caching.memorycache Not sure if this is a good thing or not? Do people use this API? Is this sufficient? |
/azp run |
Azure Pipelines could not run because the pipeline triggers exclude this branch/path. |
I didn't want to introduce another dependency. But I can try it and see what the benchmarks say. A |
32fb1e3
to
cd12eef
Compare
I tested
Both make it slower than the Here are the benchmarks with the cache variants:
The project with the benchmarks for the various variants is on https://github.com/MichaelRumpler/SkiaTextRendering. As you can see the simple |
In comparsion with the Anyway, if you access the dictionary with |
Description of Change
This enables a user to set a cache duration. When set to a value > 0, it caches the
SKShaper
and theSKShaper.Result
thus repeated calls with the same font and/or text are faster.Bugs Fixed
API Changes
Added:
public static void SetShaperCacheDuration(this SKCanvas canvas, uint milliseconds)
Behavioral Changes
If the cache duration was set to a value bigger than zero,
DrawShapedText
will cache theSKShaper
and theSKShaper.Result
for that amount of milliseconds. Therefore repeated calls with the sameSKFont
and/orstring
will be faster.If the cache duration is set to 0, then the cache will be cleared, all contained
SKShaper
objects disposed and caching will be disabled.The default cache duration is 0. So if
SetShaperCacheDuration
is never called,DrawShapedText
works as before.Required skia PR
None.
PR Checklist