Keep the message's layout until its text, width or atoms change (ATC-200) #3
Loading…
Reference in a new issue
No description provided.
Delete branch "layout-cache"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Work package: ATC-200, typing stutters in at-claude's composer.
Every
Height,Cursor,ViewandDrawwrapped the whole message again with uniseg, and ran the atom regex over every shown row's paragraph. at-claude asksHeightmany times a frame, so on a long draft each keystroke cost a frame of 130–180 ms.Removed
rows()no longer builds the rows itself.shown(), and re-segmenting each shown row with uniseg on every draw.View.Added
layout(layout.go): the wrapped rows, each paragraph's atoms, and each shown row's cells, placed lazily the first time the row is shown. Each is kept with the text, the width and the atom pattern it was built from, andlaid()builds it again when any of those three differs. The cache invalidates by comparing those three values when it is read. Callers never clear it.setParas(layout.go), the only writer ofb.paras: it counts each change to the text. All four places that changed the text now go through it:SetValue(and soReset),insert(typing, paste/Insert, new line,Replace),remove(every delete key,Replace), andrestore(Undo,Redo). Width (SetWidth) and atoms (SetAtoms) need no hook, because they are part of what the cache compares.atomflag oncell, so a kept row carries which cells are in an atom andshownonly applies the caller's styles.wrapwalks the atoms with a forward index instead of scanning them all at each grapheme.Viewbuilds each style's escape once per call.TestTheLayoutFollowsEveryChange: before each of type, new line, backspace, delete, word deletes, delete to end/start, paste,Replace,Undo,Redo,SetWidth,SetAtoms(off and on),SetValueandReset, it lays the box out. After the change, it checks the rows, atoms,Rows,Height,CursorandViewagainst a new box in the same state whose kept layout is cleared. Disabling the text count, the width key or the atom key, or bypassingsetParasat any one of its four callers, each fails it at the matching step.BenchmarkHeight,BenchmarkView,BenchmarkTypeAndViewon a 2000-character draft with atoms, width 100, 10 rows.Left alone
Value,Rows,Height,Top,Cursor,ViewandDrawoutput on main and on this branch.snap,before/afterand cursor movement, which still work on one paragraph per key.Numbers (GOMAXPROCS=4, i9-13900H laptop, main vs this branch run back to back)
HeightViewViewA keystroke now pays for one re-wrap of the message, where before every
Height,CursorandViewcall in the frame paid for one.🤖 Generated with Claude Code