Load font faces from cached bytes instead of re-reading the file per pixel size - #235
Load font faces from cached bytes instead of re-reading the file per pixel size#235handrok wants to merge 1 commit into
Conversation
|
Warning Review limit reached
Next review available in: 19 minutes Limit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits within each organization. For paid Pro and Pro+ reviews, CodeRabbit uses a developer's included PR review attempts over the past 7 days to set the current hourly allowance. At typical activity levels, the full plan allowance applies. Higher sustained activity can lower the allowance until earlier attempts leave the 7-day window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (10)
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughFont loading now uses in-memory 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
d614792 to
1bd5f29
Compare
1bd5f29 to
4e96c39
Compare
|
|
||
| for (IFontFace* face : m_loadedFaces) { | ||
| if (face->key().dataKey == dataKey && face->key().type == type && face->key().pixelSize == loadedPixelSize | ||
| if (face->key().dataKey == actualDataKey && face->key().type == type && face->key().pixelSize == loadedPixelSize |
There was a problem hiding this comment.
not necessarily, thoughts:
- We have requireDataKey and actualDataKey
- When creating FontFace, we pass both keys to it (actualDataKey as a property of FontData)
- i.e. we don't need to call actualFont, actualDataKey already has it, we just need to save it there and add a getter
- actualFont call File::exists inside - this is not good
FontsEngine is not used in Musescore, so I tested in standalone application.
After last PR #231 profiling showed clearLoadedFaces() taking ~20% of total score-open time.
FontsEngine's face cache is keyed by (family, type, pixelSize, isSymbolMode), so every distinct pixel size used in a document creates a brand-new IFontFace, which re-opens and re-reads the same font file from disk again. FT_New_Memory_Face itself is fast; the actual cost is (a) the repeated disk reads and (b) destroying all those per-pixel-size ByteArray buffers later in clearLoadedFaces().
So FontsDatabase now caches the font file's bytes once per path (fontData()), and IFontFace::load() takes those bytes directly instead of a path, so a new pixel size no longer triggers a new disk read.
The reading of font file was changing from code
to
because sequence of
file.openfile.readAll()malloc memory twice. For 5mb otf file it is a problem.