Skip to content

perf(pptx): read each font program once for a registered family's viewer metrics - #1090

Open
DemchaAV wants to merge 1 commit into
developfrom
perf/pptx-viewer-metrics-one-parse
Open

DemchaAV wants to merge 1 commit into
developfrom
perf/pptx-viewer-metrics-one-parse

Conversation

@DemchaAV

@DemchaAV DemchaAV commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Why

Before a slide is drawn, a PPTX export reads the viewer ascent of each registered family's four faces (PptxViewerMetrics.load, through Font.createFont). It read each slot's source afresh. A family registered from one file, which FontFamilyDefinition.Builder repeats in all four slots, was opened and parsed four times per deck. The program read beside it (PptxFontEmbedder.readPrograms) already skips a source whose description() it has seen.

Measured before the change, with a counting source: 4 opens per load for a one-file family; load took 9.8 ms of a ~52 ms one-page deck for Cousine (301 KB), and 26 ms of ~131 ms for Gothic A1 (2.2 MB).

What changed

  • PptxViewerMetrics.load keeps the ascent it read per description() for the four slots of one call, and answers a repeated source from it. It uses the same key as readPrograms, so the two reads agree on which slots share a program.
  • The failure path is unchanged. description() is still asked inside the same try, which now holds the lookup too. A refusal still ends the load at the first unreadable face, in slot order, and that face is the one named.
  • The deck is unchanged, byte for byte. No public API changes.

Verification

  • PptxViewerMetricsTest (new, 4 tests):
    • a source in all four slots is opened once;
    • two sources with one description are opened once;
    • four different programs each answer their own slot and are opened once each (the premise that their four ascents differ is asserted);
    • an unreadable face after a read one is still the one named.
  • Sabotage, each run through surefire with 4 tests run; the file was restored to the same sha afterwards. Each break below was caught by the test aimed at it:
    • lookup disabled;
    • cache never filled;
    • one constant key;
    • identity key instead of description.
  • A/B, a harness outside the build on the render-pptx test classpath, logging quiet (logback-benchmark.xml), base and changed classes alternating:
    • load: Cousine 9.8 → 2.3 ms; Gothic A1 26 → 5.9 ms (median of 1600, two rounds).
    • One-page deck in that family, median of 400 exports per round, two rounds: Cousine 51.3 / 54.4 → 43.3 / 45.0 ms; Gothic A1 131.3 / 131.5 → 112.4 / 111.1 ms.
  • Byte identity: every zip part of six decks has the same SHA-256 before and after (237 parts). The six decks are one-file, two-file and four-file families, two registered families, and a bundled font alone.
  • ./mvnw -B -ntp test -pl :graph-compose-render-pptx -am: core 845, render-pdf 347, testing 5, render-pptx 211 tests, 0 failures; ./mvnw -B -ntp test -f qa/pom.xml: 1927 tests, 0 failures.
  • Full gate on 5f8649272 (reactor clean verify as CI runs it, the four JDK 17 knowledge checks, core javadoc, install, examples tests): GATE PASS — reactor 6286 tests, 0 failures; examples 93 tests including CommittedAssetDriftTest, 0 failures.

Lane: render-pptx backend internals; no layout, core or public API change. No example renders a PPTX with a registered family, so no committed preview is affected.

…wer metrics

PptxViewerMetrics.load read the viewer ascent of each of a registered
family's four slots through Font.createFont, opening each slot's source
afresh. A family registered from one file repeats that file in all four
slots, so it was parsed four times per deck.

The ascent is now kept per FontBinarySource.description() for the slots
of one load, the key the program read beside it already uses. The
failure path and the deck's bytes are unchanged.

Measured with a harness outside the build, logging quiet: the metrics
read took Cousine 9.8 -> 2.3 ms and Gothic A1 26 -> 5.9 ms; a one-page
deck in that family 51-54 -> 43-45 ms and 131 -> 111-112 ms. Every part
of six decks is byte-identical before and after.
@DemchaAV
DemchaAV marked this pull request as ready for review November 26, 2026 01:22

This branch has not been deployed

No deployments
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.

1 participant