3 Commits
Author SHA1 Message Date
yetone fc75d90af7 yaml.v3: its two regexps are compiled on first use, not at launch
0caa09b3d vendored gopkg.in/yaml.v3 into third_party/yaml.v3, inside
magpie's tree, and TestNoEagerPackageRegexps, which walks the tree, has
been red on main since:

  third_party/yaml.v3/encode.go:307:19: a package-level regexp is
  compiled at launch; use lazyre.New
  third_party/yaml.v3/resolve.go:124:22: (the same)

yaml.v3 is its own module and can't import internal/lazyre, and its
go.mod has no go line (Go 1.16 language, so no sync.OnceValue).
base60float and yamlStyleFloat are now functions that compile their
expression once behind a sync.Once; the patterns are as upstream's.
MAGPIE.md lists this as the second change from v3.0.1.

Seen red in the full suite of the OpenMausBot sessions change (mote, at
13cb07fde + that change), which doesn't touch yaml.

Run (mote): gofmt -l clean; go vet in third_party/yaml.v3; go vet ./..., GOOS=linux -tags nogui and GOOS=windows go vet ./...; go test -count=1 -timeout 45m ./... at 59c5b59ea (on df2b819c6): 100 packages ok, TestNoEagerPackageRegexps among them. Red before: the two lines above, on 13cb07fde.
After a rebase onto ea6470cb7 (01c3efc4f's library change and a GUI
test): vet as above, and go test . ./internal/sessions ./internal/library
./internal/catalog ok. After another onto 79a30eb9c (edit/toml.go and
provider/remote_follow.go perf): go vet ./..., go test . ./internal/sessions
./internal/edit ./internal/provider ok, at the pushed tree.

Not run: upstream yaml.v3's own tests (not copied here, need
gopkg.in/check.v1).
2026-11-14 15:42:01 +08:00
yetone 0caa09b3d9 perf: yaml's event queue, TOMLWithout's buffer and the catalog's hash stop holding whole documents
A start with the owner's real accounts (release build, mote) allocated
279 MB in its first seven minutes; three of the largest were buffers
the size of a whole document that nothing needed whole:

- yaml.v3's emitter appends every event to a queue it never empties,
  so encoding dsh's route of a few hundred models held ~24 MB of
  events (dshPutProviders' Node.Encode and dshNodeLines). That round
  runs on the first start of each version and on each catalog change.
  yaml.v3 is vendored in third_party/yaml.v3 (replace in go.mod, as
  jsonschema is) with the queue started again once it is drained;
  MAGPIE.md says what changed. go.yaml.in/yaml/v3 v3.0.5 has the same
  queue.
- edit.TOMLWithout made its output as large as the input: 1.5 MB per
  read of Codex's config, which five readers make, to keep a few KB
  around the projects tables. It now grows to what is kept.
- catalog.fileKey read the ~6 MB catalog whole to hash it; it is now
  hashed as it is read.

Measured with the owner's real accounts (~/r2278/acct, tray only, no
window), release ldflags and the footprint overlay, a version new to
the HOME so dsh's full round runs, on mote:
- allocations in the first 7 minutes 279 MB -> 260 MB;
  yaml_emitter_emit 24.9 MB -> under pprof's cut (1.3 MB),
  dshPutProviders 23.1 -> 8.1 MB, dshNodeLines 12 MB -> under the cut,
  edit.tomlUnder 12.2 -> 4.0 MB
- footprint at +300 s 59 -> 58 MB, live heap 5.5 MB both; peak 84 vs
  89 MB, within the run-to-run spread seen before (84-88 MB)

Run at this tree: upstream yaml.v3's own tests on the patched emitter
(go test ., ok); go test ./internal/agent ./internal/cli ./internal/edit
./internal/library ./internal/pluginrt ./internal/catalog on mica (ok),
and ./internal/sessions on mote before the yaml change (ok); go vet ./...
(mac), GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...
ok; gofmt -l on the changed files prints nothing.
Not run: the full suite.
2026-11-14 14:33:16 +08:00
yetone 772f936272 perf: jsonschema's metaschemas are compiled on first use, not at launch
github.com/santhosh-tekuri/jsonschema/v6's init compiles every draft's
metaschema (4, 6, 7, 2019-09, 2020-12 and their vocabularies): ~1.7 MB
and ~21,000 allocations on every launch, the largest init left in the
binary. magpie compiles a schema only for a Claude TUI answer tool, so
`magpie statusline`, run on each Claude Code message, paid it for
nothing.

v6.0.3's non-test files are now in third_party/jsonschema (go.mod
replace; LICENSE and MAGPIE.md beside them), with one change: init
became loadDrafts behind a sync.Once, which Compiler.Compile calls
first; loadDrafts compiles the metaschemas through the unexported
compile exactly as init did. The Dockerfile copies third_party before
`go mod download`, which needs the replace's directory.

New TestAnswerSchemaCheckedAgainstItsDraft: three schemas that break
their draft (type 5, minLength "x", required "a" under 2020-12) are
refused. Broken by hand (Compile without ensureDrafts) it panics red.

Measured on mote, sandbox HOME, t45 (v0.1.3522) against t46 (this):
- GODEBUG=inittrace=1 sum: 2.98 MB / 28,515 allocs -> 1.28 MB / 7,385
- `magpie statusline`, 3 runs: instructions retired ~135M -> ~101M,
  peak memory footprint 15.5-16.1 MB -> 12.6-12.7 MB

Run: upstream's own tests (`go test .`, GOWORK=off) on the forked
draft.go and compiler.go: ok, as on upstream (36 pass; the official
JSON-Schema-Test-Suite submodule isn't in the module zip, so it wasn't
run). go vet ./... ok; GOOS=windows go vet ./internal/gateway ok;
go test -run 'TestAnswer|TestClaudeTUISchema' ./internal/gateway ok;
root TestNoEagerPackageRegexps, TestAllLazyPatternsCompile ok.
Not tried: a docker build of the Dockerfile.
2026-11-10 13:16:59 +08:00