Skip to content

Desktop: memory and binary size, race-free UI tests (#476) - #493

Merged
MopigamesYT merged 7 commits into
perf/auditfrom
perf/476-memory-size
Nov 17, 2026
Merged

MopigamesYT merged 7 commits into
perf/auditfrom
perf/476-memory-size

Conversation

@MopigamesYT

Copy link
Copy Markdown
Member

Closes #476. Stacked on #477 (perf/audit): merge that first, then retarget this to main.

What changes

  • Smaller binary — Fyne's Noto Sans and DejaVu fonts are stored gzipped and unpacked on first use. On Linux the 4.2 MB EmojiOneColor font is no longer bundled: emoji are drawn with the system's colour emoji font (Noto Color Emoji or similar), loaded the first time one appears. Windows keeps the bundled font. Behaviour change: a Linux system without any colour emoji font no longer shows colour emoji.
  • Font files parsed once — every style and theme reset used to parse the same font files again (the audit measured 17.7 MB of duplicates); the parsed faces are now shared.
  • GC pacing — GOGC 50 by default (GOGC in the environment wins). I tried a soft memory limit too and dropped it: below the live heap (a 40,000-row chat open) it made the GC run back to back and the window crawl.
  • State saved chat by chat — each save (400 ms after any change, so near-continuously while agents stream) encoded every chat into one buffer the size of the state file, grown by doubling. A real install has a 97 MB state.json, so that is a few hundred MB of garbage per save. The chats are now encoded and written one at a time through a buffered file. The file is byte-for-byte the same (new test TestWriteChatsMatchesWholeEncoding).
  • Race-free UI tests — under Fyne's test driver, fyne.Do ran on the calling goroutine, so UI work from timers and goroutines ran alongside the test. It now waits in a queue that the test goroutine runs (fyne.Do, DoAndWait, test.Drain, a new app). Only DoAndWait from another goroutine gets a 20 ms fallback runner, so it can't deadlock.

Numbers (VM 111, llvmpipe, stream benchmark, 60 s)

before after target
Release binary (-trimpath -s -w) 47.17 MB 41.92 MB < 40 MB, missed by 1.9 MB
RSS after launch (200 chats) 262 MB 234 MB
Peak RSS, 4,000-row chat streaming 536 MB 428 MB (−20 %)
Go heap / sys at end of span 159 / 337 MB 139 / 230 MB
Frames, CPU 28 fps, 157 % 27 fps, 159 % no change
go test -race ./internal/ui 632–1,075 races per run, every run killed (OOM) 0 races in 20 runs, 17/17 pass 0

The 40,000-row state (37 MB) is noisy (the UI thread takes minutes to load such a chat, in syncCopies/offsetIn, which this PR doesn't touch): peak RSS 2.31 → 1.93 GB, RSS at end of span 1.37–2.36 → 1.11 GB.

On the VM, TestDiscordArt and TestEverySettingIsMarked fail only because they read repository files by relative path; they pass in the source tree.

Not done

  • 40 MB: the rest would come from dropping SQLite (1.8 MB, only used to import Firefox cookies, which also needs the WAL file read) or forking oksvg to drop the CJK encodings (~0.6 MB). Both are feature or maintenance decisions.
  • Long chats: streaming into a very long chat still grows the heap fast (320 → 766 MB in 60 s with 40,000 rows), and opening one is slow on the UI thread. That's a separate issue.

Assisted-by: Claude Opus 5.5 low

🤖 Generated with Claude Code

…inux (#476)

Fyne's Noto Sans and DejaVu fonts are stored gzipped and unpacked on first
use. On Linux the 4.2 MB EmojiOneColor font is no longer bundled: emoji use
the system's colour emoji font, loaded the first time one is drawn. Windows
keeps the bundled font, which its own emoji font cannot replace.
Release binary: 47.2 MB to 41.9 MB.

Assisted-by: Claude Opus 5.5 low
Every style and every theme reset parsed the same font files again; the
audit measured 17.7 MB of duplicate parsed faces.

Assisted-by: Claude Opus 5.5 low
GOGC 50: a collection when the heap grows by half rather than doubles.
GOGC in the environment still wins. No memory limit: one below the live
heap (a 40,000-row chat open) made the collector run back to back on the
test VM and the window crawl.

Assisted-by: Claude Opus 5.5 low
…utine (#476)

Under Fyne's test driver, fyne.Do ran its function on the calling goroutine,
so work handed to the UI from timers and goroutines ran alongside the test:
600 to 1,100 data races per race-detector run. Work from other goroutines now
waits in a queue that the test goroutine runs (fyne.Do, DoAndWait, Drain, a
new app). Only DoAndWait from another goroutine gets a helper that runs the
queue after 20 ms, so it cannot deadlock.

Assisted-by: Claude Opus 5.5 low
Each save, 400 ms after a change, encoded every chat into one buffer the size
of the state file (97 MB on a real install), grown by doubling, then wrote it:
a few hundred MB of garbage per save while agents stream, which drove a
running 1loop past 1.4 GB of RSS. The chats are now encoded and written one
at a time through a buffered file; the file is the same, byte for byte.

Assisted-by: Claude Opus 5.5 low
No textual conflict; fixed the ring tests that waited on a fyne.Do now queued by the #476 test driver (added test.Drain).
@MopigamesYT
MopigamesYT merged commit fcb1cdc into perf/audit Nov 17, 2026
@MopigamesYT
MopigamesYT deleted the perf/476-memory-size branch November 17, 2026 10:35
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.

1 participant