Skip to content

Commit 476593e

Browse files
committed
test(alloc): gate LSPComputeDiagnostics at <=70 allocs (locks the regex-hoist win)
Co-Authored-By: Virgil <virgil@lethean.io>
1 parent c1cf230 commit 476593e

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

alloc_gate_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ var (
3232
gateBytes []byte
3333
gateResult Result
3434
gateAny any
35+
gateDiags []LSPDiagnostic
3536
)
3637

3738
func TestAllocs_HotPrimitives(t *T) {
@@ -102,3 +103,17 @@ func TestAllocs_HotPrimitives(t *T) {
102103
AssertLessOrEqual(t, avg, c.ceiling, c.name)
103104
}
104105
}
106+
107+
// TestAllocs_LSPComputeDiagnostics locks the regex-hoist win (c1cf230):
108+
// with per-call regexp.Compile it allocated ~186/call; compiling the
109+
// naming-diagnostic patterns once dropped it to ~47. A regression to
110+
// per-call compilation jumps back over 100, so the ceiling catches it.
111+
func TestAllocs_LSPComputeDiagnostics(t *T) {
112+
uri := "file:///agent/worker.go"
113+
content := []byte("package worker\n\nfunc process(in string) (string, error) {\n\treturn in, nil\n}\n")
114+
LSPComputeDiagnostics(uri, content) // warm the per-dir cache → measure steady state
115+
avg := int(testing.AllocsPerRun(200, func() {
116+
gateDiags = LSPComputeDiagnostics(uri, content)
117+
}))
118+
AssertLessOrEqual(t, avg, 70, "LSPComputeDiagnostics")
119+
}

0 commit comments

Comments
 (0)