Skip to content

Add typography benchmark tests for textToContours() - #9268

Open
LalitNarayanYadav wants to merge 3 commits into
processing:mainfrom
LalitNarayanYadav:bench/text-to-contours
Open

LalitNarayanYadav wants to merge 3 commits into
processing:mainfrom
LalitNarayanYadav:bench/text-to-contours

Conversation

@LalitNarayanYadav

@LalitNarayanYadav LalitNarayanYadav commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #8968

Changes:

  • Adds textToContours() benchmarks to test/bench/typography.bench.js, continuing Add typography performance tests #8918
  • TO_CONTOURS_CASES is derived from TO_POINTS_CASES, so the strings, text sizes and sampleFactor are identical across the textTo___ benchmarks
  • Adds a drawContours() helper for the render: true case
  • Adds the contours suite to the 2D, WebGL and WebGPU describe blocks
  • Sequences TO_CONTOURS_CASES and the contours benchmarks right after the textToPoints() ones in all 3 renderers
  • Asserts the total point count across contours matches the existing textToPoints() expectations (same sampleFactor: 0.5, same variance)
  • Asserts the expected contour count per case via EXPECTED_CONTOURS (16 for the single word, 76 for 10 words, 1167 for the paragraph)

Testing:

  • Ran npx vitest bench --run test/bench/typography.bench.js --project unit-tests-webgpu -t "textToContours". Contour counts and point totals pass in 2D, WebGL and WebGPU.
  • On my machine, the WebGPU "with render" cases don't run. This includes the existing textToPoints() and textToModel() ones, which record no samples, with Cannot read properties of undefined (reading 'createShaderModule') raised from drawContours() in the contours case. This looks like no WebGPU device being available in headless Chromium here, so those cases aren't verified locally. It would be great if someone could confirm them in CI or on another setup.

Note: in WebGL, the render case is about 10x slower than the non-render case, because drawContours() calls beginShape/endShape once per contour.

cc @shakeelmohamed for review.

Screenshots of the change:
N/A (benchmark tests only)

PR Checklist

@LalitNarayanYadav LalitNarayanYadav changed the title Add textToContours() benchmark tests Add typography benchmark tests for textToContours() Oct 10, 2026
Comment thread test/bench/typography.bench.js Outdated
);
}

for (let testCase of TO_CONTOURS_CASES) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For consistency, we might want to sequence textToContours() tests after textToPoints() in all 3 renderers

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in all 3 renderers. The order is now points, then contours, then model.

Comment thread test/bench/typography.bench.js Outdated
{label: "textToModel() paragraph", str: strs.paragraph, textSize: 20, sampleFactor: 0.5, render: false},
];

const TO_CONTOURS_CASES = TO_POINTS_CASES.map((c) => ({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Similar note RE: sequencing these after TO_POINTS_CASES

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, TO_CONTOURS_CASES now sits right after TO_POINTS_CASES

Comment thread test/bench/typography.bench.js Outdated
];

const TO_CONTOURS_CASES = TO_POINTS_CASES.map((c) => ({
...c,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I appreciate the test case reuse here. How might we also test the expected contour count?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added an EXPECTED_CONTOURS lookup, indexed like TO_POINTS_CASES, and an assert.equal on contours.length in all 3 renderers. The counts are 16 for the single word, 76 for 10 words and 1167 for the paragraph, and they’re the same in 2D, WebGL and WebGPU

@LalitNarayanYadav
LalitNarayanYadav marked this pull request as ready for review October 15, 2026 19:59
@ksen0 ksen0 added this to the 2.4 milestone Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Add typography benchmark tests for textToContours()

3 participants