Skip to content

Look up kerning pairs without building a string key - #1881

Open
g4lb wants to merge 1 commit into
foliojs:masterfrom
g4lb:perf-kerning-lookup
Open

g4lb wants to merge 1 commit into
foliojs:masterfrom
g4lb:perf-kerning-lookup

Conversation

@g4lb

@g4lb g4lb commented Nov 26, 2026

Copy link
Copy Markdown

What kind of change does this PR introduce?

Performance. AFMFont.getKernPair() made a new string key for each pair of glyphs. Now it reads a Map by left glyph, then by right glyph. The PDF output does not change.

Input Before After Change
Paragraph, Helvetica 1.94 ms 1.24 ms -36%
Long multipage text 18.9 ms 12.2 ms -36%
Table, 30 rows 5.43 ms 4.15 ms -24%

Images and vector paths did not change (M2 Max, Node 24). The first load of all 14 standard fonts uses 0.7 ms and 385 KB more.

Checklist

  • Unit tests N/A
  • Documentation N/A
  • Update CHANGELOG.md
  • Ready for review and merge

The tests pass on Node 20, 22 and 24. The PDF bytes are the same on 2,000 random documents.

@blikblum

Copy link
Copy Markdown
Member

385 KB more

What this number refers?

@g4lb

g4lb commented Nov 26, 2026

Copy link
Copy Markdown
Author

It is the JS heap after the 14 fonts load (after GC): 1,087 KB before, 1,471 KB after. The new Maps use this memory.

@g4lb
g4lb force-pushed the perf-kerning-lookup branch from 35a9337 to 83c0e6c Compare November 27, 2026 06:46

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.

2 participants