servo icon indicating copy to clipboard operation
servo copied to clipboard

Remove `InlineFormattingContext::font_metrics`

Open minghuaw opened this issue 3 weeks ago • 2 comments

In the current implementation, only block-level jobs get dispatched onto rayon thread pool during box tree construction, and I was looking into whether the current block level jobs can be further parallelized, during which I found that it's the InlineFormattingContext::font_metrics field that's stopping InlineItems in the same InlineFormattingContext from being processed in parallel.

https://github.com/servo/servo/blob/224ca771c05c0962c5f8e5a6459c0c66f6277cf4/components/layout/flow/inline/mod.rs#L153-L155

https://github.com/servo/servo/blob/224ca771c05c0962c5f8e5a6459c0c66f6277cf4/components/layout/flow/inline/mod.rs#L196-L202

font_metrics right now gets used when a TextRunSegment uses the index to get the corresponding info like metrics etc. However, these info can be easily obtained from a FontRef as well, and thus I was wondering if anyone who's familiar with the design could explain why not just store a FontRef in the TextRunSegment (and some other types if necessary)? There's always one indirection anyway whether to use a index and the font_metrics Vec or to store a FontRef

I've tried implementing this on my local machine and it seems to work fine. I can open a PR if this sounds OK.

minghuaw avatar Dec 09 '25 07:12 minghuaw

Your suggestion seems reasonable though maybe I would need to see your change to say for sure.

mrobinson avatar Dec 09 '25 14:12 mrobinson

Your suggestion seems reasonable though maybe I would need to see your change to say for sure.

I'll open a PR and let you review :)

minghuaw avatar Dec 10 '25 01:12 minghuaw

@mrobinson I've opened a draft PR #41208

minghuaw avatar Dec 11 '25 15:12 minghuaw