Skip to content

Reduce ASCII text render allocations#56

Closed
relh wants to merge 1 commit into
treeform:masterfrom
relh:relh/reduce-text-render-allocations-v2
Closed

Reduce ASCII text render allocations#56
relh wants to merge 1 commit into
treeform:masterfrom
relh:relh/reduce-text-render-allocations-v2

Conversation

@relh

@relh relh commented Jun 27, 2026

Copy link
Copy Markdown

Summary

  • build runtime-only ASCII glyph and kerning lookup tables from existing font atlas entries
  • skip those runtime tables during atlas JSON serialization so rebuilt atlases stay clean
  • route ordinary ASCII drawText / getTextSize calls through byte iteration while preserving the existing Unicode fallback path
  • apply the same measurement path to the semantic backend

Why this belongs in Silky

The hot allocations come from Silky's normal text APIs: toRunes, per-glyph $rune strings, and string-keyed kerning lookups on every ASCII label. Coworld hits this through regular text, button, checkBox, drawText, and getTextSize calls, so the fix is inside the UI library rather than Coworld glue.

This replaces closed #55 with a clean branch off upstream master. The important v2 difference is that the ASCII tables are explicitly runtime-only and are rebuilt after atlas load/build; the PR does not serialize derived cache data into atlas metadata.

Downstream proof

Coworld follow-up PR: https://github.com/Metta-AI/coworld-vanilla-wow/pull/453

90-frame replay command, from Coworld player/:

nim r -d:ProfileTracePath=/tmp/coworld-rework-v2-90.json -d:ProfileTicks=90 global_viewer.nim -- --replay=../docs/examples/plainstrider-session-replay.json

Last 30 render frame events:

Pin set render frame avg render frame alloc avg render UI alloc avg global UI alloc avg
merged main / #399 pins 28.839 ms 856.1 850.1 790.0
GLTF v2 + upstream Silky 29.044 ms 16349.5 16343.5 15821.0
GLTF v2 + Silky v2 28.812 ms 856.1 850.1 790.0

Interpretation: upstream Silky confirms the text allocation regression is real; this cleaned Silky v2 recovers the allocation win without the bad #55 branch shape.

Verification

  • nim check --path:src src/silky/atlas.nim
  • nim check --path:src src/silky/contexts.nim
  • nim check --path:src src/silky/semantic.nim
  • nim r --hints:off --warnings:off --path:src --eval:... assertion that asciiEntries, asciiKerning, and asciiFallback are absent from SilkyAtlas.toJson()
  • downstream Coworld nim check global_viewer.nim
  • downstream Coworld nim check player.nim

@treeform

Copy link
Copy Markdown
Owner

I like your PR here, but I fixed it in a more general way in this PR: #57

Instead of June, just ASCII, I did it for all Unicode characters.

@treeform treeform closed this Jun 28, 2026
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