Skip to content

[Feature] nsgo dev: hot-swap literal edits (sizes, colors, text) in the running app in milliseconds, without a rebuild #660

Closed

Description

@houko

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:

  1. Rewrite in dev builds only. When dev builds, it parses the app's own packages (not dependencies) and, through go's -overlay (which goBuild already 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. 16 becomes devlit.Int(0x1a2b, 16). Literals in constant declarations, array lengths, struct tags, switch cases and other places that must stay constant are left alone. nsgo build takes no such overlay, so release output is byte-for-byte what it is today.
  2. Decide per save whether a rebuild is needed. On a change, dev parses the old and new file and compares the syntax trees with the rewritable literals masked out. Equal trees mean only literals changed: dev sends 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.
  3. 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.
  4. 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

Acceptance

  • Under nsgo dev on 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 build output 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 dev targets
  • NSGo: main at 468ba6c (2026-11-18)
  • Development machine: macOS 27.2 (Apple M4 Pro, 12 cores), Go 1.27.3

Activity

  1. self-assigned this
    on Nov 20, 2026
  2. houko commented on Nov 20, 2026

    @houko
    CollaboratorAuthor

    The current nsgo dev path rebuilds and restarts native Go apps on source changes, while TSX has a separate CompileHot path. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions