Skip to content

Speed up Balsa HTTP/1 token validation#45186

Open
benni-rogge wants to merge 1 commit into
envoyproxy:mainfrom
benni-rogge:speed-up-balsa-header-token-validation
Open

Speed up Balsa HTTP/1 token validation#45186
benni-rogge wants to merge 1 commit into
envoyproxy:mainfrom
benni-rogge:speed-up-balsa-header-token-validation

Conversation

@benni-rogge
Copy link
Copy Markdown

@benni-rogge benni-rogge commented May 20, 2026

Commit Message:
Speed up Balsa HTTP/1 token validation

Additional Description:
Replace the per-character binary search used for Balsa HTTP/1 token validation with a constexpr bit mask. Header field names and custom methods still use the RFC 9110 token character set, but the hot path now does a fixed-index mask lookup for each byte.

Testing:

  • bazel test -c opt //test/common/http/http1:balsa_parser_test //test/common/http/http1:balsa_parser_benchmark_test //test/common/http/http1:codec_impl_test
  • git diff --check

Benchmark:
Command used for both baseline and optimized runs:
bazel run -c opt //test/common/http/http1:balsa_parser_benchmark -- --benchmark_filter=bmParseHeaders --benchmark_min_time=0.25s --benchmark_repetitions=10 --benchmark_out=<file>.json --benchmark_out_format=json

Shape Headers Baseline mean Optimized mean CPU reduction 95% CI
long 8 1724.6 ns 1051.0 ns 39.06% 37.59%..40.52%
long 16 3238.2 ns 1832.0 ns 43.42% 42.81%..44.03%
long 64 12156.5 ns 6246.1 ns 48.62% 47.04%..50.20%
long 256 47039.9 ns 24059.3 ns 48.85% 48.25%..49.46%
long 512 97201.0 ns 48013.2 ns 50.60% 49.46%..51.75%
short 8 531.1 ns 497.9 ns 6.26% 5.38%..7.14%
short 16 850.9 ns 744.9 ns 12.46% 11.61%..13.31%
short 64 2540.0 ns 2066.9 ns 18.62% 17.76%..19.48%
short 256 9711.9 ns 7381.7 ns 23.99% 23.50%..24.49%
short 512 19393.7 ns 14645.0 ns 24.49% 23.91%..25.06%
full-token-set 8 4054.1 ns 1984.0 ns 51.06% 49.85%..52.27%
full-token-set 16 7796.9 ns 3646.6 ns 53.23% 52.41%..54.05%
full-token-set 64 29938.3 ns 13281.4 ns 55.64% 55.13%..56.15%
full-token-set 256 120034.2 ns 51514.2 ns 57.08% 56.45%..57.72%
full-token-set 512 240048.1 ns 102724.5 ns 57.21% 56.72%..57.70%

Signed-off-by: Benni Rogge <benni.rogge@shopify.com>
@repokitteh-read-only
Copy link
Copy Markdown

Hi @benni-rogge, welcome and thank you for your contribution.

We will try to review your Pull Request as quickly as possible.

In the meantime, please take a look at the contribution guidelines if you have not done so already.

🐱

Caused by: #45186 was opened by benni-rogge.

see: more, trace.

@benni-rogge benni-rogge requested a deployment to external-contributors May 20, 2026 15:31 — with GitHub Actions Waiting
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.

1 participant