Commit Graph
3 Commits
Author SHA1 Message Date
yetone 99299c7b1c edit: the big-TOML ratio test compares 1 MB with 8 MB under a bound of 24 (#2219)
36200091a (Niko-Wu's patch from #2219, picked as written) bounds the
8 MB parse by 8 times the 2 MB one, 2x room on each side of the linear
4x and the quadratic 16x. On mote at load 250 it went red 1 run in 13:
load didn't slow both parses alike. The sizes are now 1 MB and 8 MB, so
linear is 8x and quadratic 64x, and the bound of 24 leaves about 3x on
each side; each size keeps the fastest of five parses.

Run on mote (macOS 27), at this tree:
- go test -tags nogui -count=30 -run TestTOMLBigFile ./internal/edit at
  load 214: ok.
- Broken by hand, tomlShaper's line found by a scan from the top of the
  file (the per-key pass 2a4042a9 removed): red, "an 8 MB file took
  1m52.9s to parse, 71.4x the 1 MB one's 1.58s". Reverted.
- gofmt -l clean.
Still a timing test: it measures a ratio, not a count, since the parse
has no counter to read without adding one to toml.go.
2026-10-29 01:11:18 +08:00
Niko WuandClaude Code 36200091ad edit: the big-TOML shape test bounds the parse by two sizes' time ratio, not one second of wall clock (#2219)
edussss on 10-15, running `go test -tags nogui ./...` for #1928 at load
average ~190: TestTOMLBigFileParsesInLinearTime went red, a 3 MB file
took 1.272s against the 1s bound. Rerun alone it passes. The parse was
still linear; the bound was not.

The check now parses a 2 MB and an 8 MB file three times each, keeps
the fastest of each, and requires the 8 MB time to stay under 8 times
the 2 MB one. Load slows both parses together, so their ratio holds
where a wall-clock second does not. The code standards' "a timing test
leaves room on both sides" asked for exactly this: measured here, the
linear parse's ratio is 3.7 to 4.5, and the quadratic parse the test
guards against, which counts each key's line from the top of the file,
needs 16 times the time for the 4 times bigger file. 8 sits between
the two, far from both.

What was run:
- go test -tags nogui ./internal/edit/: ok
- the fixed test with -count=3: ok (6 runs)
- a local quadratic tomlShaper (per-key line scan, the behavior
  2a4042a9 removed): the ratio reads 16.0x (2 MB 5.3s, 8 MB 1m25s)
  and the test goes red; reverted after
- gofmt -l internal/edit/: empty
- go vet -tags nogui ./internal/edit/ at GOOS=windows and GOOS=linux
  (the latter CGO_ENABLED=0; the local macOS SDK has no glibc, so the
  cgo path of a dependency cannot be vetted here): clean

No .github/, site/ or go.mod/go.sum file is touched.

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-10-29 00:57:54 +08:00
yetone 2a4042a94d perf: magpie opens and shows the Agents page in a fraction of the time it took (Junjie Zhou on Discord: 8 个 agent 30 个 provider … 每次我打开的时候都会很慢,要好几秒。setting 页面秒进后 我切换到 agent 就有问题) — at start, writing the agents' model lists (agent.SyncCatalog) built every provider's catalog thousands of times with nothing held, each build reading migrations.json, settings and groups again: 6000+ file reads and ~8.5s of CPU in the first 8s with the owner's 30-odd providers, all competing with the first /api/state and the Agents page. Now SyncCatalog, magpieModels and main's start-up moves run under provider.Hold, migrations, groups, settings and a provider's fetched models are held for a second like the rest, and filememo.Hold lets a GET /api/* not stat a file it confirmed unchanged within the last second (any magpie write, Changed() or a recent mtime still reads it again). A big ~/.codex/config.toml parsed in quadratic time (the TOML parser's Shape counts newlines from the start for every key): a 3 MB one took 5.4s, now 0.04s (tomlShaper). theInstalled reads through edit.Read's memo. Measured with a copy of the owner's magpie config and agent configs under a sandbox HOME, the real server in WebKit: CPU in the first 8s 8.59s → 0.39s, page up 475 → 75ms, Agents rows drawn 775 → 325ms after start; the agents' written model files are unchanged (pi byte for byte, opencode the same models). TestTOMLShaperMatchesParser, TestTOMLBigFileParsesInLinearTime (fails on the old code), TestHold (filememo), TestHoldReadsMigrationsOnce. go vet, builds (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass. 2026-10-05 03:02:40 +08:00