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.
This commit is contained in:
yetone
2026-10-29 01:11:18 +08:00
parent 36200091ad
commit 99299c7b1c
+11 -10
View File
@@ -54,13 +54,13 @@ func tomlBigFile(size int) []string {
return splitLines("model_provider = \"x\"\n" + b.String())
}
// parseTOMLTimed parses lines three times and keeps the fastest, which a
// parseTOMLTimed parses lines five times and keeps the fastest, which a
// loaded runner can still reach, and the file it read.
func parseTOMLTimed(t *testing.T, lines []string) (tomlFile, time.Duration) {
t.Helper()
var f tomlFile
var best time.Duration
for rep := 0; rep < 3; rep++ {
for rep := 0; rep < 5; rep++ {
start := time.Now()
got, err := parseTOMLFile(lines)
if err != nil {
@@ -78,16 +78,17 @@ func parseTOMLTimed(t *testing.T, lines []string) (tomlFile, time.Duration) {
// square: Codex's own reached 1.5 MB, and each key's line was counted from
// the top of the file, a third of a second at every magpie start.
//
// The check is the ratio between parsing a 2 MB and an 8 MB file, not a bound
// The check is the ratio between parsing a 1 MB and an 8 MB file, not a bound
// in seconds: a runner at load ~190 took the still-linear 3 MB parse past the
// old 1s bound and went red without anything quadratic (#2219). Load slows
// both parses together, not their ratio. A parse that grows with size squared
// needs 16× the time for the 4× bigger file, where the linear one needs 4×,
// so the bound sits between the two, far from both.
// both parses, if not always alike. A parse that grows with size squared
// needs 64× the time for the 8× bigger file, where the linear one needs 8×,
// so the bound of 24 leaves about 3× on both sides: at 2 MB and 8 MB with a
// bound of 8 (2× each side), mote at load 250 went red 1 run in 13.
func TestTOMLBigFileParsesInLinearTime(t *testing.T) {
small, large := tomlBigFile(2<<20), tomlBigFile(8<<20)
small, large := tomlBigFile(1<<20), tomlBigFile(8<<20)
f, dSmall := parseTOMLTimed(t, small)
if len(f.tables) < 30000 || f.root.keys[0].name != "model_provider" {
if len(f.tables) < 10000 || f.root.keys[0].name != "model_provider" {
t.Fatalf("parsed %d tables, root %+v", len(f.tables), f.root.keys)
}
last := f.tables[len(f.tables)-1]
@@ -95,7 +96,7 @@ func TestTOMLBigFileParsesInLinearTime(t *testing.T) {
t.Errorf("last key %+v of %d lines", k, len(small))
}
_, dLarge := parseTOMLTimed(t, large)
if ratio := float64(dLarge) / float64(dSmall); ratio > 8 {
t.Errorf("an 8 MB file took %v to parse, %.1f× the 2 MB one's %v: near the 16× of size squared, not the 4× of size", dLarge, ratio, dSmall)
if ratio := float64(dLarge) / float64(dSmall); ratio > 24 {
t.Errorf("an 8 MB file took %v to parse, %.1f× the 1 MB one's %v: near the 64× of size squared, not the 8× of size", dLarge, ratio, dSmall)
}
}