Repository navigation
Description
Context
Iterating on a Go UI under nsgo dev costs a full rebuild and restart per save (cmd/nsgo/dev.go:157-159 on main at 468ba6c). That is seconds at best: Go links a native GUI binary every time, then the process starts and draws its first frame. #658 measured 1.6–2.8 s for examples/hello and 9–29 s for examples/gallery on a busy 12-core M4 Pro; an idle machine is faster, but no Go edit that goes through compile, link and restart can reach the tens of milliseconds a React or TSX update takes. TSX already gets there (tsx/bundler.CompileHot updates the running app in place), at the price of running interpreted in release builds.
Most edits made while tuning a screen, however, change only literals: a padding from 16 to 20, a color, a font size, a corner radius, a label's text, a duration. Those need no new machine code.
Why it matters
Tuning a UI is dozens of small edits in a row. At seconds per edit, with the window and the page lost on each (#658), it is the part of NSGo development that feels slowest next to web frameworks, and it is exactly the part that can be made instant without touching what ships.
Proposal
Hot-swap literals in nsgo dev, as data, with the release build unchanged:
- Rewrite in dev builds only. When
devbuilds, it parses the app's own packages (not dependencies) and, through go's-overlay(whichgoBuildalready passes,cmd/nsgo/build.go:610-615, today only to add files to the main package), replaces each basic literal in function bodies (numbers, strings, and the arguments of color helpers) with a lookup keyed by its position, e.g.16becomesdevlit.Int(0x1a2b, 16). Literals in constant declarations, array lengths, struct tags, switch cases and other places that must stay constant are left alone.nsgo buildtakes no such overlay, so release output is byte-for-byte what it is today. - Decide per save whether a rebuild is needed. On a change,
devparses the old and new file and compares the syntax trees with the rewritable literals masked out. Equal trees mean only literals changed:devsends the changed values over the connection the app already has (devServer.send,cmd/nsgo/dev.go:565, which carries TSX bundles today) and builds nothing. Any other difference falls back to the current rebuild. - Update only what read them. In the app, each rewritten literal is backed by a signal (
core.NewSignal), created lazily the first time its position is read, so a new value re-runs exactly the components and style functions that read it. Windows, navigation and the rest of the state stay as they are. - Keep positions stable. A literal's key is its file and its index among the rewritable literals in that file, so it survives edits elsewhere in the file; after a rebuild the table starts from the new source.
Strings that are catalog keys (i18n) can go through the same path, so editing a message updates it in place too.
Relationship to other issues
- Literal edits: this issue, milliseconds, no release cost.
- Structural Go edits (new components, logic, types): rebuild and restart, with the window and state kept (nsgo dev: a Go change closes the app's window and opens a new one, losing its place on screen (tiling, Split View) and the page it was on #658).
- One component in fixture states without the app around it: previews ([Feature] Component previews in nsgo dev: show one component with fixture state, rebuilt on save, without restarting the app #659).
Acceptance
- Under
nsgo devon the native target and the web, changing only a number, string or color literal in a component of the app updates the running app without a build, within 100 ms of the save, keeping the window, navigation and state. - Any non-literal change rebuilds as today.
-
nsgo buildoutput is identical with and without this feature. - Constants and other positions Go requires to be constant are never rewritten, so a dev build compiles whenever the release build does.
- Platforms: all
devtargets - NSGo: main at 468ba6c (2026-11-18)
- Development machine: macOS 27.2 (Apple M4 Pro, 12 cores), Go 1.27.3
Activity
houko commentedon Nov 20, 2026
The current
nsgo devpath rebuilds and restarts native Go apps on source changes, while TSX has a separateCompileHotpath. The proposed Go literal hot-swap requires a source transformer that preserves Go constant semantics, stable source keys, runtime signal storage, a dev transport for literal updates, AST diffing, and coordinated support for native and web targets. It also needs a clear rule for literals whose values affect control flow or APIs, beyond the listed constant contexts. This is a compiler/runtime project rather than a safe focused patch, so I am closing the issue until that design is split into implementable stages.