Add benchmark (CEL vs FIELD vs Direct) filter_state access#6797
Add benchmark (CEL vs FIELD vs Direct) filter_state access#6797PetrMc wants to merge 1 commit intoistio:masterfrom
Conversation
| setupCelFilterState(stream_info); | ||
|
|
||
| // CEL format: %CEL(filter_state.downstream_peer.workload)% | ||
| const std::string format = "%CEL(filter_state.downstream_peer.workload)%"; |
There was a problem hiding this comment.
Thanks for testing it. I suspect there's some hidden allocation here that's causing most of the hit. I'd expect it to be up to 3x slower but not 30x.
There was a problem hiding this comment.
thanks @kyessenov i run it on debug build on Linux VM - so the results certainly not precise. Any suggestions on how to get more accurate measurements?
There was a problem hiding this comment.
You should use release config to benchmark. If you use tcmalloc, there's an alloc profiler that you can utilize to find it. Are you trying to optimize CEL? FIELD will always be faster.
There was a problem hiding this comment.
thanks i'll do that. for the context we implemented FIELD Accessor here istio/istio#58348 as it seem to be the right architecture decision and now working on confirming that the change is justified in terms of performance. We had a side discussion with @zirain on that topic #6765 (comment) and need to make sure all questions are addressed.
There was a problem hiding this comment.
yeah, if it's 30x faster, FIELD is a reasonable new feature.
If it's just 3x in ns level, which make no sense to store another object in memory.
There was a problem hiding this comment.
done optimized build and 3 runs below all show consistent over 30x difference.
run 1
INFO: Found 1 target...
Target //source/extensions/filters/http/peer_metadata:filter_state_benchmark up-to-date:
bazel-bin/source/extensions/filters/http/peer_metadata/filter_state_benchmark
INFO: Elapsed time: 8622.036s, Critical Path: 534.99s
INFO: 2440 processes: 143 internal, 2297 processwrapper-sandbox.
INFO: Build completed successfully, 2440 total actions
INFO: Running command line: bazel-bin/source/extensions/filters/http/peer_metadata/filter_state_benchmark
2026-01-28T10:38:29-08:00
Running /home/ubuntu/.cache/bazel/_bazel_ubuntu/7f61383ba1c4bb725390614e1c03ab26/execroot/io_istio_proxy/bazel-out/k8-opt/bin/source/extensions/filters/http/peer_metadata/filter_state_benchmark
Run on (8 X 1567.25 MHz CPU s)
CPU Caches:
L1 Data 48 KiB (x4)
L1 Instruction 32 KiB (x4)
L2 Unified 1280 KiB (x4)
L3 Unified 24576 KiB (x1)
Load Average: 4.35, 7.64, 9.20
***WARNING*** ASLR is enabled, the results may have unreproducible noise in them.
--------------------------------------------------------------------------------
Benchmark Time CPU Iterations UserCounters...
--------------------------------------------------------------------------------
BM_FilterState_CEL 5302 ns 5277 ns 129492 bytes_per_second=47.5332Mi/s alloc_per_iter=263B
BM_FilterState_FIELD 128 ns 128 ns 6817691 bytes_per_second=1.91971Gi/s alloc_per_iter=263B
BM_FilterState_Direct 21.9 ns 21.9 ns 31837857 bytes_per_second=348.119Mi/s alloc_per_iter=0B (no allocation, direct access)
[external/com_google_absl/absl/flags/internal/flag.cc : 147] RAW: Restore saved value of envoy_quic_always_support_server_preferred_address to: true
[external/com_google_absl/absl/flags/internal/flag.cc : 147] RAW: Restore saved value of envoy_reloadable_features_runtime_initialized to: false
run 2
$ bazel run -c opt //source/extensions/filters/http/peer_metadata:filter_state_benchmark
INFO: Analyzed target //source/extensions/filters/http/peer_metadata:filter_state_benchmark (1 packages loaded, 6 targets configured).
INFO: Found 1 target...
Target //source/extensions/filters/http/peer_metadata:filter_state_benchmark up-to-date:
bazel-bin/source/extensions/filters/http/peer_metadata/filter_state_benchmark
INFO: Elapsed time: 3.604s, Critical Path: 0.14s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Running command line: bazel-bin/source/extensions/filters/http/peer_metadata/filter_state_benchmark
2026-01-28T10:40:35-08:00
Running /home/ubuntu/.cache/bazel/_bazel_ubuntu/7f61383ba1c4bb725390614e1c03ab26/execroot/io_istio_proxy/bazel-out/k8-opt/bin/source/extensions/filters/http/peer_metadata/filter_state_benchmark
Run on (8 X 1791.25 MHz CPU s)
CPU Caches:
L1 Data 48 KiB (x4)
L1 Instruction 32 KiB (x4)
L2 Unified 1280 KiB (x4)
L3 Unified 24576 KiB (x1)
Load Average: 1.83, 5.38, 8.15
***WARNING*** ASLR is enabled, the results may have unreproducible noise in them.
--------------------------------------------------------------------------------
Benchmark Time CPU Iterations UserCounters...
--------------------------------------------------------------------------------
BM_FilterState_CEL 3985 ns 3980 ns 133361 bytes_per_second=63.0244Mi/s alloc_per_iter=263B
BM_FilterState_FIELD 118 ns 118 ns 7033442 bytes_per_second=2.08059Gi/s alloc_per_iter=263B
BM_FilterState_Direct 16.9 ns 16.9 ns 31438278 bytes_per_second=450.314Mi/s alloc_per_iter=0B (no allocation, direct access)
[external/com_google_absl/absl/flags/internal/flag.cc : 147] RAW: Restore saved value of envoy_quic_always_support_server_preferred_address to: true
[external/com_google_absl/absl/flags/internal/flag.cc : 147] RAW: Restore saved value of envoy_reloadable_features_runtime_initialized to: false
run 3
INFO: Analyzed target //source/extensions/filters/http/peer_metadata:filter_state_benchmark (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //source/extensions/filters/http/peer_metadata:filter_state_benchmark up-to-date:
bazel-bin/source/extensions/filters/http/peer_metadata/filter_state_benchmark
INFO: Elapsed time: 1.721s, Critical Path: 0.45s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Running command line: bazel-bin/source/extensions/filters/http/peer_metadata/filter_state_benchmark
2026-01-28T10:40:44-08:00
Running /home/ubuntu/.cache/bazel/_bazel_ubuntu/7f61383ba1c4bb725390614e1c03ab26/execroot/io_istio_proxy/bazel-out/k8-opt/bin/source/extensions/filters/http/peer_metadata/filter_state_benchmark
Run on (8 X 1400.36 MHz CPU s)
CPU Caches:
L1 Data 48 KiB (x4)
L1 Instruction 32 KiB (x4)
L2 Unified 1280 KiB (x4)
L3 Unified 24576 KiB (x1)
Load Average: 1.69, 5.29, 8.11
***WARNING*** ASLR is enabled, the results may have unreproducible noise in them.
--------------------------------------------------------------------------------
Benchmark Time CPU Iterations UserCounters...
--------------------------------------------------------------------------------
BM_FilterState_CEL 2764 ns 2763 ns 199363 bytes_per_second=90.7722Mi/s alloc_per_iter=263B
BM_FilterState_FIELD 70.3 ns 70.3 ns 9706858 bytes_per_second=3.48362Gi/s alloc_per_iter=263B
BM_FilterState_Direct 21.4 ns 21.4 ns 46790167 bytes_per_second=355.875Mi/s alloc_per_iter=0B (no allocation, direct access)
[external/com_google_absl/absl/flags/internal/flag.cc : 147] RAW: Restore saved value of envoy_reloadable_features_runtime_initialized to: false
[external/com_google_absl/absl/flags/internal/flag.cc : 147] RAW: Restore saved value of envoy_quic_always_support_server_preferred_address to: true
What this PR does / why we need it:
we need clear understanding of the resources used by different methods.
Which issue this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)format, will close that issue when PR gets merged): fixes istio/istio#58868Special notes for your reviewer:
on my local machine is acting not consistantly but i get similar memory use but FIELD is outperforming CEL by approximately 34x (run 1) and 49x (run 2).
attempt 1:
attempt 2: