Skip to content

Conversation

@simonklee
Copy link
Contributor

Yoga calls measureForDimensions repeatedly during layout. This adds caching
keyed by (buffer, epoch, width, wrap_mode) to avoid repeated rope walks.

  • Use epoch instead of dirty flag since other code paths clear dirty
  • Reuse measure arena with retain_capacity to reduce mmap churn during streaming
  • Add fast path for width=0 or wrap_mode=.none that skips virtual line calculation

I can split up the arena-reuse if you prefer that in another PR.

…ions

Cache measureForDimensions by (buf, epoch, width, wrap_mode) so
Yoga remeasure calls avoid repeated rope walks even when dirty
flags are cleared or buffers switch.

Reuse the measure arena with retain_capacity to avoid mmap churn
during streaming. For width==0 or wrap_mode==.none, compute max
width by scanning marker line widths to handle multi-seg lines.
simonklee and others added 2 commits January 5, 2026 18:18
Relaxed perf test threshold (3x -> 5x) to handle CI runner variability.
The 5x threshold still catches O(n^2) regressions effectively.
@remorses
Copy link
Contributor

remorses commented Jan 5, 2026

See this PR for something similar. Notice I had to measure with the max height otherwise there were some visual bugs, like in opencode the absolutely positioned autocomplete was appearing out of place, did you already test if that works in opencode with this branch?

@kommander
Copy link
Collaborator

@remorses are these issues you had reproducible with a test maybe?
@simonklee I migrated over some tests as I was working on this on another branch as well, but your implementation is better.

@kommander
Copy link
Collaborator

@remorses I can't reproduce an issue with the autocomplete position on this branch.

@kommander
Copy link
Collaborator

Taking this over #456 for having it in native, plus the arena fix.

@kommander kommander merged commit 23e8ab8 into anomalyco:main Jan 5, 2026
4 checks passed
@simonklee
Copy link
Contributor Author

Thanks @kommander, for adding the typescript integration tests and merging. I haven't really gotten around looking into that part of the code much yet so it wasn't on my mind that it was a possibility. I originally started looking into this based on the anomalyco/opencode#6172 issue. I felt this PR was about as minimal as you can go with mitigation the issue, without rewriting things to consider only the viewport or something like that.

@remorses
Copy link
Contributor

remorses commented Jan 5, 2026

Cool! What is the performance increase after this change?

@kommander
Copy link
Collaborator

~50x performance improvement for static content, according to the benchmark from ~90ms to ~1.5ms.

msmps pushed a commit that referenced this pull request Jan 8, 2026
---------

Co-authored-by: Sebastian Herrlinger <hasta84@gmail.com>
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.

3 participants