Skip to content

Text: shaping stops redoing work from the same inputs - #782

Merged
Hona merged 1 commit into
devfrom
text2
Nov 12, 2026
Merged

Hona merged 1 commit into
devfrom
text2

Conversation

@Hona

@Hona Hona commented Nov 12, 2026

Copy link
Copy Markdown
Member

Rune's vendored parley_engine stops redoing three pieces of shaping work from identical inputs. Layouts are unchanged; a text's shaping takes 14% less.

  • Segmenters: Analyzer keeps the ICU line and word segmenters it made. Making one loaded the complex-script dictionaries again for every text.
  • Run metrics: Shaper keeps each run's font metrics per font instance and size (an LRU of 16 beside its shaper caches), instead of skrifa::Metrics::new per run.
  • Style metrics: FontMetrics::from_font_instance (parley's style metrics call it per style per layout) keeps its answers per thread, 64 entries.

Proof

  • Identical: every layout of 7 screens x 11 UI languages (en ar he ja zh ko th km my hi ru, 5,933 texts) digested (line boxes, runs, fonts, sizes, coordinates, every glyph's id and position, clusters, inline boxes): 0 differ, each cache alone and together.
  • Per text (warm Parley build, the variants interleaved in one batch): 25.8 us -> 24.4 (segmenters) -> 22.1 (and metrics).
  • A returning user's launch (tabs10, release, visible desktop, n=9, p50): texts shaped between the first frame and live content 9,433 -> 7,254 us; before the first frame 1,897 -> 1,689 us.

vendor/parley_engine.patch is regenerated from the published crate plus the whole vendored tree (it applies cleanly to parley_engine 0.12.0 and reproduces vendor/parley_engine/src).

Three caches in Rune's vendored parley_engine (vendor/parley_engine.patch, beside the UAX #9 L1
fix), each for work shaping repeated from identical inputs:

- Analyzer keeps the ICU line and word segmenters it made (analysis.rs Segmenters). Making one
  looked up its rules and, with complex-scripts, loaded the dictionaries, for every text. The
  segmenters are 'static and Copy, so a kept one is the value a new one would be.
- Shaper keeps each run's font metrics per font instance and size (run_metrics_cache, an LRU of
  16 beside its shaper caches), instead of skrifa::Metrics::new for every run.
- FontMetrics::from_font_instance, which parley's style metrics call once per style per layout,
  keeps its answers per thread (64 entries, keyed by blob id, index, synthesis, size and
  variations).

Proof, every layout of 7 screens x 11 UI languages (en ar he ja zh ko th km my hi ru; 5,933
texts), a digest of each finished layout (line boxes, runs, fonts, sizes, coordinates, every
glyph's id and position, clusters, inline boxes): 0 differ, each cache alone and together.
Warm cost per Parley build, the three variants interleaved in one batch: 25.8 us a text -> 24.4
(segmenters) -> 22.1 (and metrics), 14.3% less. A returning user's launch (tabs10, release,
visible desktop, n=9): the texts shaped between the first frame and live content 9,433 -> 7,254
us p50, those before the first frame 1,897 -> 1,689.
Copilot AI balanced review requested due to automatic review settings November 12, 2026 12:15
@Hona
Hona merged commit fc01675 into dev Nov 12, 2026
@Hona
Hona deleted the text2 branch November 12, 2026 12:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

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