gateway: the facts' allocation bound is checked when not under -race (#3956)
TestChatAndMessagesFactsLeaveTheHistory (9a888323a, #3472) was red every time under -race on ubuntu and macOS CI fromec6c2de52on; earlier runs hid it, as their Test step was red and the Race step never ran. regexp keeps its backtracker in a sync.Pool, and under -race sync.Pool lets a quarter of what is put in it go, so userSaid's matches over a long conversation made new ones: a memory profile of readFacts alone shows regexp.(*bitState).reset at 13.61 MB over five reads under -race, 0.07 MB without. The bound is now skipped under raceOn, as its sibling at parse_memo_test.go:71 already is for workDirIn's regexps. Run at origin/main833f51adc+ this change, on mote: - go test -race -run TestChatAndMessagesFacts -count=3 ./internal/gateway/: ok, 3 of 3. Before the change: FAIL 3 of 3 (chat 3851848 bytes against a parse's 4524408). - go test -run TestChatAndMessagesFacts -count=3 ./internal/gateway/: ok (facts 980072 bytes against 4503336, the bound unchanged). - go vet ./internal/gateway/: ok. gofmt -l: none. Not run: the full gateway race shards; CI runs them.
This commit is contained in:
@@ -242,7 +242,10 @@ func TestChatAndMessagesFactsLeaveTheHistory(t *testing.T) {
|
||||
facts := allocated(func() { readFacts(proto, body) })
|
||||
parsed := allocated(func() { _, _ = parse(proto, body) })
|
||||
t.Logf("%s: %d-byte body, facts allocated %d bytes, the whole parse %d", proto, len(body), facts, parsed)
|
||||
if facts*3 > parsed {
|
||||
// Under -race, sync.Pool drops a quarter of what is put in it, and
|
||||
// userSaid's regexps take their backtrackers from one, so a long
|
||||
// conversation's facts make ~2.7 MB more of them (#3956).
|
||||
if !raceOn && facts*3 > parsed {
|
||||
t.Errorf("%s: facts allocated %d bytes, a third or more of the whole parse's %d", proto, facts, parsed)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user