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.
754 B
754 B
jsonschema v6.0.3, as magpie builds it
github.com/santhosh-tekuri/jsonschema/v6 v6.0.3 (Apache-2.0, LICENSE here),
its non-test files as released, with one change: the drafts' metaschemas
are compiled the first time a schema is (Compiler.Compile calls
ensureDrafts), not in init. Upstream's init cost every magpie launch
~1.7 MB and ~21,000 allocations though most compile no schema.
Changed files: draft.go (init -> loadDrafts behind sync.Once), compiler.go (Compile ensures the drafts; loadDrafts compiles through the unexported compile). go.mod's replace points here.
To take a new upstream version: copy its non-test files over these and
make the same change again; upstream's own tests (go test . in the
module, GOWORK=off) pass on it.