From cb167fcbd82d2766d73a1349c9911806023c4142 Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 29 Oct 2026 00:14:17 +0800 Subject: [PATCH] usage: CodexModelEffort's allocation bar is a packed row a call, not a visit (#2278) TestCodexModelEffortLetsUnrelatedCallsGo held a build of CodexModelEffort to a visit of the log and a half. Since dc6f6d902 a visit decodes into a lent buffer, and allocated 74 KB or 289 KB as the pool kept that buffer through the test's GC or not, so the bar moved under a build of ~430 KB and the test was red now and then (1 of 2 runs on mote at the change below, "a build allocated 430336 bytes, a visit 73848"). The bar is now what #2776 was about: a build over 3000 unrelated calls allocates less than one packed row (216 B) for each of them, 648 KB. Builds measured 215 to 430 KB. Run at this head, on mote: - go test ./internal/usage -run TestCodexModelEffortLetsUnrelatedCallsGo -count=30: ok. - go test ./internal/usage -timeout 45m: ok (23.2s). Not tried: reverting #2776's fix to see the bar go red. --- internal/usage/codex_effort_rows_test.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/internal/usage/codex_effort_rows_test.go b/internal/usage/codex_effort_rows_test.go index 979de8d6b..b1a699de5 100644 --- a/internal/usage/codex_effort_rows_test.go +++ b/internal/usage/codex_effort_rows_test.go @@ -8,6 +8,7 @@ import ( "slices" "testing" "time" + "unsafe" "github.com/yetone/magpie/internal/sessions" ) @@ -88,11 +89,15 @@ func TestCodexModelEffortLetsUnrelatedCallsGo(t *testing.T) { if got := CodexModelEffort(All); len(got["main-a"]) != 1 { t.Fatalf("main-a's consumption: %+v", got) } - visit := measure(func() { Visit(time.Time{}, func(Record) {}) }) + // a packed row a call: the bar was a visit of the log, but a visit + // decodes into a lent buffer now (#2278), and took 74 KB or 289 KB as + // a pool kept it or not + rows := uint64(calls+1) * uint64(unsafe.Sizeof(packedRow{})) build := measure(func() { CodexModelEffort(All) }) - t.Logf("a build allocated %d bytes, a visit %d", build, visit) - // the visit itself, the thread's own rows and the sets of its ids - if build > visit+visit/2+256<<10 { - t.Fatalf("a build over %d unrelated calls allocated %d bytes, a visit of the log %d", calls, build, visit) + t.Logf("a build allocated %d bytes, the log's rows are %d", build, rows) + // the thread's own rows and the sets of its ids, less than a packed + // row for each unrelated call + if build > rows { + t.Fatalf("a build over %d unrelated calls allocated %d bytes, a packed row each is %d", calls, build, rows) } }