Skip to content

perf(auth): avoid per-byte URI formatting - #172

Merged
ovaistariq merged 2 commits into
mainfrom
perfloop-pr-open-hf56qadr4h
Aug 20, 2026
Merged

ovaistariq merged 2 commits into
mainfrom
perfloop-pr-open-hf56qadr4h

Conversation

@perfloop

@perfloop perfloop Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Build canonical query pairs in one buffer and write percent escapes directly with uppercase hexadecimal digits instead of formatting an intermediate string for each escaped byte.

The buffer reserves for worst-case escaping rather than adding a byte-counting prepass. SigV4 sorting, unreserved-byte handling, and encodeSlash behavior remain unchanged. The focused benchmarks cover reserved query keys and values through the signing passthrough path.

Testing

  • make lint-ci
  • make test-auth
  • make test-proxy

Workload: reserved-byte canonical query validation

Metric Before After Change
ns/op 3014 504.6 83.3% lower
B/op 808 256 68.3% lower
allocs/op 34 1 97.1% lower

Workload: signed passthrough with reserved query keys and values

Metric Before After Change
ns/op 36971 30868 16.5% lower
B/op 16599 15503 6.6% lower
allocs/op 273 195 28.6% lower
Checks: 3 passed.

Generated by Perfloop. Measurements and checks.


Note

Low Risk
Performance-only refactor on the signing/validation hot path with parity tests and benchmarks; SigV4 sorting and encoding rules are intended to be unchanged.

Overview
Canonical query string building is refactored for fewer allocations: signer and validator now share canonicalQueryString, which writes sorted key=value pairs into one pre-sized strings.Builder instead of building intermediate strings per pair.

SigV4 percent-encoding adds writeAWSURIEncoded so awsURIEncode and canonical queries write %XX escapes via a hex lookup table rather than fmt.Sprintf per byte.

Tests and benchmarks add shared fixtures for reserved query keys/values (slashes, spaces, +, Unicode) across signer and validator, plus auth and proxy passthrough benchmarks on heavily escaped queries.

Reviewed by Cursor Bugbot for commit f45288e. Bugbot is set up for automated code reviews on this repo. Configure here.

@greptile-apps

greptile-apps Bot commented Aug 20, 2026

Copy link
Copy Markdown

Greptile Summary

The PR optimizes SigV4 canonical-query construction by sharing one implementation between signing and validation and writing percent escapes directly into a preallocated buffer.

  • Replaces per-byte formatting and intermediate query-pair strings with direct buffer writes.
  • Preserves sorted keys and values, uppercase percent escapes, unreserved-byte handling, and slash behavior.
  • Adds focused correctness tests and benchmarks for reserved query keys and values.

Confidence Score: 5/5

The PR appears safe to merge with no actionable correctness, security, or compatibility regressions identified.

The shared implementation preserves the previous byte-wise SigV4 encoding and sorting behavior across both request validation and upstream re-signing while removing intermediate allocations.

Important Files Changed

Filename Overview
auth/signer.go Introduces the shared, allocation-efficient canonical-query and URI-encoding implementation without changing observable SigV4 output.
auth/validator.go Delegates validator canonical-query construction to the same implementation used by the signer, preventing algorithm drift.
auth/signer_test.go Adds signer-and-validator coverage for reserved bytes, duplicate values, empty values, Unicode, spaces, slashes, and percent signs.
auth/signer_benchmark_test.go Adds a focused allocation benchmark that first verifies canonical output correctness.
proxy/forwarder_signing_benchmark_test.go Adds end-to-end signing-passthrough benchmark coverage for escaped query keys and values.

Reviews (1): Last reviewed commit: "perf(auth): avoid per-byte URI formattin..." | Re-trigger Greptile

@ovaistariq
ovaistariq merged commit 6a9ef9a into main Aug 20, 2026
11 checks passed
@ovaistariq
ovaistariq deleted the perfloop-pr-open-hf56qadr4h branch August 20, 2026 06:58
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 20, 2026
@tigrisdata-argocd-bot

Copy link
Copy Markdown

🎉 This PR is included in version 1.18.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants