Skip to content
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 cache for Skija fonts #144

Merged
merged 1 commit into from
Mar 12, 2025
Merged

Add cache for Skija fonts #144

merged 1 commit into from
Mar 12, 2025

Conversation

HeikoKlare
Copy link

No description provided.

Copy link

github-actions bot commented Mar 6, 2025

Test Results

   338 files  ±0     338 suites  ±0   2m 9s ⏱️ -13s
 3 954 tests ±0   3 670 ✅ ±0  284 💤 ±0  0 ❌ ±0 
11 690 runs  ±0  10 805 ✅ ±0  885 💤 ±0  0 ❌ ±0 

Results for commit fda6dcc. ± Comparison against base commit 2300249.

♻️ This comment has been updated with latest results.

@ddscharfe
Copy link

I can confirm that this removes the bottleneck.

However I would propose to make the cache thread safe (e.g. use ConcurrendHashMap).

@HeikoKlare HeikoKlare force-pushed the skija-fontcache branch 2 times, most recently from 24338cf to bd1e736 Compare March 6, 2025 16:11
@HeikoKlare
Copy link
Author

However I would propose to make the cache thread safe (e.g. use ConcurrendHashMap).

Good pointer. The PR was originally only intended for demonstration purposes but it seems to be almost usable as is. I accordingly adapted the map to be thread-safe.

@HeikoKlare HeikoKlare marked this pull request as ready for review March 6, 2025 16:12
@ddscharfe
Copy link

@HeikoKlare, did you consider that this might become a memory leak, because the cache is never cleared?

@HeikoKlare
Copy link
Author

did you consider that this might become a memory leak, because the cache is never cleared?

Yes, that might be a result if fonts are created for very many font data. However, I consider this (1) unlikely and (2) this cache is only necessary as long as we use a combination of native and Skia fonts (i.e., as long as we still use native widgets as default). Once we completely switch to Skia, the existing font caching mechanisms will directly be applied to Skia fonts instead of native fonts. That's why I think we could accept this potential leak for now, in particular since I think it would not be that easy to define a reasonable cleanup mechanism.

@ddscharfe
Copy link

did you consider that this might become a memory leak, because the cache is never cleared?

Yes, that might be a result if fonts are created for very many font data. However, I consider this (1) unlikely and (2) this cache is only necessary as long as we use a combination of native and Skia fonts (i.e., as long as we still use native widgets as default). Once we completely switch to Skia, the existing font caching mechanisms will directly be applied to Skia fonts instead of native fonts. That's why I think we could accept this potential leak for now, in particular since I think it would not be that easy to define a reasonable cleanup mechanism.

The only straightforward mechanism I can think of is to use weak references, but since this issue will disappear after the complete switch, I agree that it's acceptable to tolerate the potential leak for now.

@HeikoKlare HeikoKlare merged commit 451e42a into master Mar 12, 2025
5 checks passed
@HeikoKlare HeikoKlare deleted the skija-fontcache branch March 12, 2025 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants