pomerium/config/policy_export_test.go
Joe Kralicky 18cb47421a
Optimize Policy RouteID and Checksum
This significantly optimizes the (*Policy).RouteID() and
(*Policy).Checksum() methods for both speed and memory usage.

A new method (*Policy).ChecksumWithID(uint64) can be used to skip a call
to RouteID() if the ID is already known. Checksum() is implemented in
terms of this new method, and will always recompute the route ID on each
call.

RouteID() does not allocate heap memory. Checksum() may allocate heap memory,
depending on which fields are set. If all of the following are true,
Checksum() makes zero allocations:
1. The policy uses redirect or direct-response mode
2. The policy has no sub-policies
3. The policy has no response header rewrite config
2024-11-05 15:59:39 -05:00

14 lines
229 B
Go

package config
import (
"runtime/debug"
"sync"
"github.com/valyala/bytebufferpool"
)
func DebugResetPools() {
checksumBufferPool = bytebufferpool.Pool{}
policyPool = sync.Pool{New: policyPool.New}
debug.FreeOSMemory()
}