Skip to content

Conversation

@HALQME
Copy link
Owner

@HALQME HALQME commented Dec 26, 2025

This pull request introduces several improvements and new features, primarily focused on performance profiling, scalability testing, and incremental FFI communication for the layout engine. It adds new profiling scripts for virtual scrolling, refactors the scalability profiler for more accurate and synchronous measurements, and implements incremental FFI operations with dirty checking in the layout engine. Additionally, the roadmap is updated to reflect completed optimizations.

Profiling and Scalability Improvements:

  • Added a new example (examples/virtual-list.ts) demonstrating efficient rendering of a 50,000-item virtualized list with keyboard navigation and windowed scrolling.
  • Introduced a new profiling script (scripts/profiler-scroll.spec.ts) to measure and assert the performance of windowed scrolling with large lists, ensuring frame times remain below 16.7ms for 60 FPS.
  • Refactored the scalability profiler (scripts/profiler-limit.spec.ts) to use synchronous frame driving, improved node count scaling, and removed reliance on file output for internal measurements, increasing accuracy and repeatability. [1] [2] [3]

Layout Engine Enhancements:

  • Implemented incremental FFI operation support in the layout engine, including dirty checking for styles and children, new helpers for style serialization, and new FFI bindings for applying incremental operations. [1] [2] [3] [4] [5] [6]

Documentation Updates:

  • Updated the Japanese roadmap (docs/roadmap.ja.md) to mark FFI communication optimization, virtual scrolling, fast scroll region support, and fatal error safety net as completed.

Most important changes:

Profiling and Examples

  • Added examples/virtual-list.ts to demonstrate performant virtual scrolling of 50,000 items with keyboard navigation.
  • Added scripts/profiler-scroll.spec.ts for automated profiling and validation of windowed scrolling performance with large lists.
  • Refactored scripts/profiler-limit.spec.ts for more precise and synchronous scalability testing, improving measurement accuracy and test reliability. [1] [2] [3]

Layout Engine

  • Implemented incremental FFI operations and dirty checking in src/layout-engine/index.ts, including new helpers for style/children serialization and new FFI bindings for efficient updates. [1] [2] [3] [4] [5] [6]

Documentation

  • Updated docs/roadmap.ja.md to reflect completion of key architecture and optimization milestones, including FFI efficiency and large-scale rendering support.

Move text and block rendering before the outline so borders and outlines are
drawn last and always overlay content. Remove duplicate rendering block at the
end of the function. Preserve stack='z' behavior and compute child clip from
padding.
Detect vertical content shifts and emit a DECSTBM scroll prefix to perform fast
terminal scrolls. Map previous row indices to avoid redrawing scrolled lines and
track scrollOps in DiffStats. Also update render paths, improve ANSI sanitize
regex, and add unit tests.
Introduce a view/dirty module and proxy-based tracking for style and children
mutations. Renderer now samples dirty versions and the hasScrollRegion hint to
skip layout/collect traversals and short- circuit renders when nothing changed.
Add renderer.invalidate and call it from LoopManager cleanup. Make
TextElement.content setter mark render-only dirty to avoid unnecessary layout.
Reconcile next immediate-mode ViewElement trees into the retained previous tree
to preserve object identities and avoid spurious dirty marks. Add reconcileTree
and setDirtyVersions, export a retained cache, optimize BaseView key/identifier
setters, adjust windowed/virtual-list layout, and add a test to ensure unchanged
frames are skipped.
Reduce excessive cursor moves by batching printable text into a pending buffer
and flushing only when control sequences are emitted. Introduce
pushCtl/flushText/moveTo helpers and an "inRun" fast-path to coalesce adjacent
glyph writes. Add renderFullRedraw and renderFullRedrawAscii for size changes
(update stats and preserve scrollPrefix behavior). Update tests to reflect
batched output and new cursor move counts
Introduce ViewportSlice primitive for rendering visible list slices. Add
getWindowedMetrics and clampWindowedStartIndex; Windowed now uses
terminal-height fallback and delegates to ViewportSlice. Update examples, tests,
and profiler script to use the new APIs.
Use a scheduler with queueMicrotask and a `scheduled` flag so the render effect
is run at most once per microtask cycle. Add a unit test that verifies multiple
reactive updates are coalesced into a single additional render.
Add RenderDiff.scrollOp to apply an explicit DECSTBM scroll (with
normalization/validation) so callers can skip scroll detection. In the render
loop restrict DECSTBM to a single scroll region, return the scroll op from the
fast scroll path, and introduce a dirty-rect path that reuses previous buffers
when only render props change. Update map collection logic and add unit tests
for both behaviors.
Mark layout dirty when Text content changes if width or height are
auto/undefined. Add a test that verifies the renderer re-runs layout when
intrinsic text content changes and adjust an existing test to use explicit
sizing.
Add an uncaughtException listener that restores terminal state (show cursor,
disable bracketed paste, and perform cleanup without clearing) to avoid leaving
the TTY in raw mode after fatal errors. The listener removes itself on cleanup
and rethrows the error asynchronously if it's the only listener to preserve
default runtime behavior. Include a unit test and update the roadmap checkbox.
@HALQME HALQME merged commit bf2f7b8 into main Dec 27, 2025
2 checks passed
@HALQME HALQME deleted the optimize-arch branch December 27, 2025 06:49
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