Skip to content

perf(components): bound Markdown construction to the viewport - #117

Merged
sudoevolve merged 1 commit into
sudoevolve:devfrom
Linductor-alkaid:perf/markdown-viewport
Oct 23, 2026
Merged

sudoevolve merged 1 commit into
sudoevolve:devfrom
Linductor-alkaid:perf/markdown-viewport

Conversation

@Linductor-alkaid

Copy link
Copy Markdown
Contributor

问题

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 dev 22f0ca35d19c06e989d64998ce18a27101ffd55c.

修改

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:

Font / workload Baseline Viewport
Bundled TTF / steady 88.246 / 90.208 0.693 / 0.842
Bundled TTF / append 88.625 / 91.130 22.240 / 22.680
Noto Sans SC CFF / steady 95.153 / 96.614 0.739 / 0.793
Noto Sans SC CFF / append 94.791 / 96.608 25.253 / 25.700

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.

影响

  • 6 modified / 6 added / 0 deleted files; 645 insertions / 35 deletions.
  • Self-owned source net +467 lines (including the measurement Python script); tracked content net +52,277 bytes.
  • No new product dependency, resource, generated source or binary. Raw benchmark JSON is review evidence required for performance changes.
  • Additive public API, exercised by installed two-translation-unit consumers.

本机环境

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:

  • GLFW + OpenGL: full build, CTest 38 passed; installed SDK 1 passed.
  • SDL2 + OpenGL: full build, CTest 38 passed; installed SDK 1 passed.
  • GLFW + Vulkan: full build, CTest 37 passed + 1 explicit skip; installed SDK 1 passed.
  • SDL2 + Vulkan: full build, CTest 37 passed + 1 explicit skip; installed SDK 1 passed.
  • Actual viewer mapped, wheel-scrolled and closed cleanly in all four combinations; screenshots reviewed.
  • Geometry regression: leaf IDs/text/frames/full height; fractional offsets, widths, CJK/Latin/emoji, themes/font sizes, headings/quotes/lists/code/tables; 18 KiB paragraph and 100-row table node bounds; edits/replacement/font changes/cache churn. Final viewport unit reruns passed in all four builds.
  • OpenGL exact RGBA comparison for twelve theme/DPI/scroll combinations. OpenGL-only readback returns skip 77 on Vulkan; geometry/viewer coverage runs there. No Vulkan pixel-equivalence claim.
  • Header unit compiled with ASAN (leak detection) and UBSAN: passed without reports, linking uninstrumented Release core. This is not whole-library sanitizer coverage.
  • Paired performance raw data and reproduction harness; harness itself rerun successfully.
  • git diff --check.

@sudoevolve
sudoevolve merged commit 32e2928 into sudoevolve:dev Oct 23, 2026
4 checks passed
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