Repository navigation
Description
Context
Tree.SetEnvironment (core/tree.go:711-723) sets the environment's signals in one batch, marks layout when the safe area or the header heights changed, and then calls t.markAll() unconditionally (core/tree.go:722, under the comment "Images pick their scales, screens their headers from it."). markAll sets t.full (core/tree.go:854-857), which commitRound turns into fullRound (core/commit.go:196). resolve then forces every node (core/commit.go:307) and marks it (:330), and emit compares every view (self := n.dirty || t.fullRound, core/commit.go:673). Layout is not redone: relayoutAll runs only on a pixel ratio change (core/commit.go:202-207).
Marking everything on an environment change is documented: "What every node reads (the environment, the layout direction, the font scale, an accessory's ID) marks them all." (docs/architecture/core.md:85). Reporting the window frame through the environment is documented too: "Frame reports the frame SetWindowFrame takes, through the environment, so an app reads it as an Env signal." (docs/architecture/services.md:250).
The cost comes from the trigger being every report, including reports where only fields that no node reads changed:
- macOS observes
NSWindowDidMoveNotification(internal/platform/macos/macos.go:1020), andrefreshsendsSetEnvironmentwheneverenv.Equalfails (macos.go:1004-1007).WindowFrameis part of that environment (macos.go:965), so every move is a change. - A window-controls transition calls
refresh()on each frame it moves the traffic lights (internal/platform/macos/desktop.go:148-152), andTitleBar's left edge follows the zoom button's frame (desktop.go:363-369), so each frame is a change. - Windows sends
SetEnvironmentonwmMovewhenever the frame changed (internal/platform/windows/windows.go:2402-2405).
In core, windowFrame, maximized, lifecycle and titleBar are set in Env.set (core/env.go:146-149, :173) and read only through their Env accessors, which already track them per field; nothing in resolve or emit reads them. Class variants follow the environment through tracked reads as well (Tree.classEnv, core/classes.go:144-149). The engine merges queued environment messages for the same surface (internal/engine/engine.go:583), so this is one full resolve and emit per engine pass during a drag, not one per move message.
Why it matters
Dragging a window or running a controls transition costs a walk of the whole tree on the engine goroutine every pass, although nothing any view shows changed. That goes against the rule in the same paragraph of core.md:85, "A commit costs what changed, not what the tree is". docs/architecture/performance.md:52 shows the scale of the difference for 300 static rows: 4 µs per marked commit against 572 µs when commits walked the whole tree. That older figure includes layout, which a full round here skips, so a full resolve and emit costs less, but it still grows with the tree instead of with what changed.
Proposal
Keep the documented rule (what every node reads marks them all) and keep WindowFrame, Maximized, Lifecycle and TitleBar as Env signals.
- In
SetEnvironment, compare the previous report (t.reported, already stored atcore/tree.go:712) with the new one, and callmarkAllonly when a field that resolve or emit reads directly changed: the pixel ratio and font scale (whichcommitRoundalready checks), the header heights, and whatever image variant selection reads. KeepmarkLayoutfor the safe area and headers as today. Fields read only throughEnvaccessors propagate through their signals. - Optionally, carry window frame, maximized and lifecycle changes as messages of their own that set the same signals, so a move never travels the full environment path.
Acceptance
- A
SetEnvironmentthat changes onlyWindowFrame,Maximized,LifecycleorTitleBarcommits without a full round; a test asserts that, and a benchmark of window moves over a large tree shows a cost that does not grow with the tree. - Changes to pixel ratio, font scale, header heights, dark mode, RTL and the other fields views depend on still update every affected node (the existing environment tests stay green).
Activity
houko commentedon Nov 20, 2026
I implemented the environment diff in PR #1000.
Tree.SetEnvironmentnow keeps WindowFrame, Maximized, Lifecycle, and TitleBar changes on the signal-driven incremental path, while changes to fields the core reads directly still request a full resolve. Regression tests cover both paths.go tool nsgo test -run 'TestWindowEnvironment' -timeout 3mandgo tool nsgo check -jobs 2pass.PR: #1000