Skip to content

Conversation

@sayrer
Copy link
Contributor

@sayrer sayrer commented Jan 23, 2026

This change adds a dfaTransitions field to nfaBuffers and uses it in valueMatcher.transitionOn() instead of allocating a new slice for each value match operation. The buffer is reset to length 0 before each use while preserving capacity. See #470.

Reliable reduction in allocations.

Before:

 % go test -bench=^Benchmark8259Example$ -run=^$ 
FA: Field matchers: 2 (avg size 2.500, max 4)
Value matchers: 5
SmallTables 20371 (splices 6, avg 4.033, max 66, epsilons avg 0.001, max 2) singletons 1
97182/sec
goos: darwin
goarch: arm64
pkg: quamina.net/go/quamina
cpu: Apple M1 Ultra
Benchmark8259Example-20    	  127725	     10290 ns/op	     984 B/op	      31 allocs/op
PASS
ok  	quamina.net/go/quamina	1.620s

After:

% go test -bench=^Benchmark8259Example$ -run=^$                    
FA: Field matchers: 2 (avg size 2.500, max 4)
Value matchers: 5
SmallTables 20371 (splices 6, avg 4.033, max 66, epsilons avg 0.001, max 2) singletons 1
100830/sec
goos: darwin
goarch: arm64
pkg: quamina.net/go/quamina
cpu: Apple M1 Ultra
Benchmark8259Example-20    	  130026	      9918 ns/op	     914 B/op	      23 allocs/op
PASS
ok  	quamina.net/go/quamina	1.628s

This change adds a dfaTransitions field to nfaBuffers and uses it in
valueMatcher.transitionOn() instead of allocating a new slice for each
value match operation. The buffer is reset to length 0 before each use
while preserving capacity.
The buffer is used for both DFA and NFA traversal, so the more
generic name transitionsBuf is more accurate.
@sayrer sayrer changed the title Pool DFA transitions buffer in nfaBuffers to reduce allocations Pool transitions buffers to reduce allocations Jan 23, 2026
Copy link
Owner

@timbray timbray left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like PRs that only touch 2 files. Tbh I'm surprised at the size of the effect. Good stuff!

@timbray timbray merged commit 46af03e into timbray:main Jan 23, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants