Skip to content

Reuse initialized cel.Env across fuzz iterations in fuzzing - #1606

Merged
dmitriplotnikov merged 1 commit into
cel-expr:masterfrom
dmitriplotnikov:fuzz-reuse-env
Nov 5, 2026
Merged

dmitriplotnikov merged 1 commit into
cel-expr:masterfrom
dmitriplotnikov:fuzz-reuse-env

Conversation

@dmitriplotnikov

@dmitriplotnikov dmitriplotnikov commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator
  • Cache getCELFuzzEnv using sync.OnceValues so FuzzParser, FuzzChecker, FuzzCompile, FuzzInterpreter, and FuzzEval reuse the initialized *cel.Env instead of rebuilding standard library declarations, type registries, and parser options on every fuzz input (OSS-Fuzz issue 578817974 #1592).
  • Hoist getCELFuzzEnv() outside the per-input closure in FuzzParser, add regression seed inputs, and add BenchmarkFuzzParserIter.

Benchmarks (go test -bench=^BenchmarkFuzzParserIter$ -benchmem)

goos: linux · goarch: amd64 · pkg: cel.dev/cel-go/fuzzing · cpu: Intel(R) Xeon(R) CPU @ 2.20GHz

Benchmark before.txt (sec/op) after.txt (sec/op) vs base
FuzzParserIter-8 7.567µ ± 14% 2.614µ ± 7% -65.46% (p=0.002 n=6)
Benchmark before.txt (B/op) after.txt (B/op) vs base
FuzzParserIter-8 2.954Ki ± 0% 1.211Ki ± 0% -59.01% (p=0.002 n=6)
Benchmark before.txt (allocs/op) after.txt (allocs/op) vs base
FuzzParserIter-8 61.00 ± 0% 31.00 ± 0% -49.18% (p=0.002 n=6)

- Cache `getCELFuzzEnv` using `sync.OnceValues` so `FuzzParser`, `FuzzChecker`, `FuzzCompile`, `FuzzInterpreter`, and `FuzzEval` reuse the initialized `*cel.Env` instead of rebuilding standard library declarations, type registries, and parser options on every fuzz input (cel-expr#1592).
- Hoist `getCELFuzzEnv()` outside the per-input closure in `FuzzParser`, add regression seed inputs, and add `BenchmarkFuzzParserIter`.

Benchmarks (`go test -bench=^BenchmarkFuzzParserIter$ -benchmem`):

goos: linux
goarch: amd64
pkg: cel.dev/cel-go/fuzzing
cpu: Intel(R) Xeon(R) CPU @ 2.20GHz
                 │  before.txt  │             after.txt              │
                 │    sec/op    │   sec/op     vs base               │
FuzzParserIter-8   7.567µ ± 14%   2.614µ ± 7%  -65.46% (p=0.002 n=6)

                 │  before.txt  │              after.txt              │
                 │     B/op     │     B/op      vs base               │
FuzzParserIter-8   2.954Ki ± 0%   1.211Ki ± 0%  -59.01% (p=0.002 n=6)

                 │ before.txt │             after.txt             │
                 │ allocs/op  │ allocs/op   vs base               │
FuzzParserIter-8   61.00 ± 0%   31.00 ± 0%  -49.18% (p=0.002 n=6)
@dmitriplotnikov
dmitriplotnikov merged commit 38b3ca4 into cel-expr:master Nov 5, 2026
8 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