Repository navigation
perf(components): bound Markdown construction to the viewport - #117
Merged
sudoevolve merged 1 commit intoOct 23, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
Scrolling Markdown constructs the entire DSL tree for a long paragraph, even when few lines are visible. An 18 KiB paragraph produces ~9,000 controls. Each inline segment also copies the entire source run, making long-run storage quadratic. Reproduce with the paired harness in
docs/benchmarks/markdown-viewport-20261023.md; baseline is upstream dev22f0ca35d19c06e989d64998ce18a27101ffd55c.修改
Add opt-in
MarkdownBuilder::viewport(top, height, overscan=32)in document-local logical coordinates. Preserve full bounds and leaf IDs; build nearby blocks, table rows and inline lines. Reuse parsed documents/inline geometry via exact-source/metric keys and a UI-thread-local LRU (8 entries / 8 MiB accounted / 4 MiB maximum retained entry). Font-file configuration revision invalidates metric caches. Inline segments retain only rendered metadata.Omission preserves complete construction. Existing parsing/layout/rendering remain authoritative. Callers clip and recompose on scroll; consumers deriving selection from controls request a complete build on selection start. API, cache bounds and selection limits are documented; viewer demonstrates scrolling. No worker, dependency or font is added.
性能证据
Same machine/Release compiler/link configuration, old/current Markdown headers linked to one identical current core library. 18 KiB CJK/Latin/emoji paragraph, width 420, viewport 500/180; 5 warmups + 60 samples; three AB/BA/AB rounds. Median of per-run p50/p95, ms:
Nodes: 9003–9005 → 400 TTF / 432 CFF. Raw chronological samples, font/binary hashes, RSS and runnable paired compiler harness are committed under
docs/benchmarks/. This measures CPU construction/layout/teardown, not GPU frames or a 60 FPS guarantee. Changed text still reparses/layouts; large code blocks retain existing text-control behavior.影响
本机环境
Ubuntu 24.04, Linux 7.0.0-38-generic; Intel Core Ultra 5 225H, 30 GiB RAM; GCC 13.3.0, CMake 3.28.3/Ninja. Window/pixel checks: private Xvfb/Mesa llvmpipe, SDL forced to X11. No Windows or hardware-GPU performance claim.
验证
Independent local Release directories, fixtures enabled, apps/user apps/tray disabled:
git diff --check.