Skip to content

Removes reflection from RouteContext to reduce allocations#6820

Merged
arkodg merged 5 commits intoenvoyproxy:mainfrom
mathetake:translate
Sep 9, 2025
Merged

Removes reflection from RouteContext to reduce allocations#6820
arkodg merged 5 commits intoenvoyproxy:mainfrom
mathetake:translate

Conversation

@mathetake
Copy link
Copy Markdown
Member

goos: darwin
goarch: arm64
pkg: github.com/envoyproxy/gateway/test/fuzz
cpu: Apple M1 Pro
                          │   old.txt    │               new.txt               │
                          │    sec/op    │   sec/op     vs base                │
GatewayAPItoXDS/small-10    881.2µ ±  7%   813.4µ ± 8%   -7.69% (p=0.023 n=10)
GatewayAPItoXDS/medium-10   4.130m ± 26%   3.214m ± 4%  -22.17% (p=0.000 n=10)
GatewayAPItoXDS/large-10     5.375 ±  2%    4.585 ± 1%  -14.69% (p=0.000 n=10)
geomean                     26.94m         22.89m       -15.06%

                          │   old.txt    │               new.txt                │
                          │     B/op     │     B/op      vs base                │
GatewayAPItoXDS/small-10    507.2Ki ± 0%   500.1Ki ± 0%   -1.40% (p=0.000 n=10)
GatewayAPItoXDS/medium-10   2.545Mi ± 7%   2.138Mi ± 2%  -15.98% (p=0.000 n=10)
GatewayAPItoXDS/large-10    2.832Gi ± 0%   2.831Gi ± 0%        ~ (p=0.436 n=10)
geomean                     15.40Mi        14.47Mi        -6.09%

                          │   old.txt   │               new.txt               │
                          │  allocs/op  │  allocs/op   vs base                │
GatewayAPItoXDS/small-10    8.328k ± 0%   8.185k ± 0%   -1.71% (p=0.000 n=10)
GatewayAPItoXDS/medium-10   39.45k ± 6%   33.25k ± 1%  -15.70% (p=0.000 n=10)
GatewayAPItoXDS/large-10    38.75M ± 0%   38.73M ± 0%   -0.05% (p=0.000 n=10)
geomean                     233.5k        219.3k        -6.09%

@codecov
Copy link
Copy Markdown

codecov bot commented Aug 19, 2025

Codecov Report

❌ Patch coverage is 72.86432% with 54 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.03%. Comparing base (c19352e) to head (98248bd).
⚠️ Report is 39 commits behind head on main.

Files with missing lines Patch % Lines
internal/gatewayapi/contexts.go 69.49% 49 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6820      +/-   ##
==========================================
- Coverage   71.04%   71.03%   -0.01%     
==========================================
  Files         225      225              
  Lines       39810    39912     +102     
==========================================
+ Hits        28282    28352      +70     
- Misses       9859     9891      +32     
  Partials     1669     1669              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mathetake
Copy link
Copy Markdown
Member Author

mathetake commented Aug 19, 2025

goos: darwin
goarch: arm64
pkg: github.com/envoyproxy/gateway/test/gobench
cpu: Apple M1 Pro
                          │   old.txt    │               new.txt               │
                          │    sec/op    │   sec/op     vs base                │
GatewayAPItoXDS/small-10    881.2µ ±  7%   803.4µ ± 1%   -8.82% (p=0.000 n=10)
GatewayAPItoXDS/medium-10   4.130m ± 26%   2.959m ± 4%  -28.36% (p=0.000 n=10)
GatewayAPItoXDS/large-10     5.375 ±  2%    4.553 ± 1%  -15.28% (p=0.000 n=10)
geomean                     26.94m         22.12m       -17.90%

                          │   old.txt    │               new.txt                │
                          │     B/op     │     B/op      vs base                │
GatewayAPItoXDS/small-10    507.2Ki ± 0%   492.9Ki ± 0%   -2.83% (p=0.000 n=10)
GatewayAPItoXDS/medium-10   2.545Mi ± 7%   1.954Mi ± 2%  -23.21% (p=0.000 n=10)
GatewayAPItoXDS/large-10    2.832Gi ± 0%   2.831Gi ± 0%        ~ (p=0.529 n=10)
geomean                     15.40Mi        13.97Mi        -9.31%

                          │   old.txt   │               new.txt               │
                          │  allocs/op  │  allocs/op   vs base                │
GatewayAPItoXDS/small-10    8.328k ± 0%   8.017k ± 0%   -3.73% (p=0.000 n=10)
GatewayAPItoXDS/medium-10   39.45k ± 6%   29.74k ± 2%  -24.60% (p=0.000 n=10)
GatewayAPItoXDS/large-10    38.75M ± 0%   38.71M ± 0%   -0.11% (p=0.000 n=10)
geomean                     233.5k        209.8k       -10.16%

@mathetake mathetake marked this pull request as ready for review August 20, 2025 08:41
@mathetake mathetake requested a review from a team as a code owner August 20, 2025 08:41
@mathetake mathetake changed the title bench: adds APIToXDS bench & small opt Removes reflection from RouteContext to reduce allocations Aug 20, 2025
goos: darwin
goarch: arm64
pkg: github.com/envoyproxy/gateway/test/gobench
cpu: Apple M1 Pro
                          │   old.txt    │               new.txt               │
                          │    sec/op    │   sec/op     vs base                │
GatewayAPItoXDS/small-10    881.2µ ±  7%   803.4µ ± 1%   -8.82% (p=0.000 n=10)
GatewayAPItoXDS/medium-10   4.130m ± 26%   2.959m ± 4%  -28.36% (p=0.000 n=10)
GatewayAPItoXDS/large-10     5.375 ±  2%    4.553 ± 1%  -15.28% (p=0.000 n=10)
geomean                     26.94m         22.12m       -17.90%

                          │   old.txt    │               new.txt                │
                          │     B/op     │     B/op      vs base                │
GatewayAPItoXDS/small-10    507.2Ki ± 0%   492.9Ki ± 0%   -2.83% (p=0.000 n=10)
GatewayAPItoXDS/medium-10   2.545Mi ± 7%   1.954Mi ± 2%  -23.21% (p=0.000 n=10)
GatewayAPItoXDS/large-10    2.832Gi ± 0%   2.831Gi ± 0%        ~ (p=0.529 n=10)
geomean                     15.40Mi        13.97Mi        -9.31%

                          │   old.txt   │               new.txt               │
                          │  allocs/op  │  allocs/op   vs base                │
GatewayAPItoXDS/small-10    8.328k ± 0%   8.017k ± 0%   -3.73% (p=0.000 n=10)
GatewayAPItoXDS/medium-10   39.45k ± 6%   29.74k ± 2%  -24.60% (p=0.000 n=10)
GatewayAPItoXDS/large-10    38.75M ± 0%   38.71M ± 0%   -0.11% (p=0.000 n=10)
geomean                     233.5k        209.8k       -10.16%

Signed-off-by: Takeshi Yoneda <[email protected]>
Signed-off-by: Takeshi Yoneda <[email protected]>
Signed-off-by: Takeshi Yoneda <[email protected]>
Signed-off-by: Takeshi Yoneda <[email protected]>
Copy link
Copy Markdown
Contributor

@arkodg arkodg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks !

@arkodg arkodg merged commit b1f23d7 into envoyproxy:main Sep 9, 2025
51 of 53 checks passed
@mathetake mathetake deleted the translate branch September 9, 2025 16:35
zirain pushed a commit to zirain/gateway that referenced this pull request Sep 16, 2025
…y#6820)

* bench: adds APIToXDS bench & small opt

Signed-off-by: Takeshi Yoneda <[email protected]>

* no refect

goos: darwin
goarch: arm64
pkg: github.com/envoyproxy/gateway/test/gobench
cpu: Apple M1 Pro
                          │   old.txt    │               new.txt               │
                          │    sec/op    │   sec/op     vs base                │
GatewayAPItoXDS/small-10    881.2µ ±  7%   803.4µ ± 1%   -8.82% (p=0.000 n=10)
GatewayAPItoXDS/medium-10   4.130m ± 26%   2.959m ± 4%  -28.36% (p=0.000 n=10)
GatewayAPItoXDS/large-10     5.375 ±  2%    4.553 ± 1%  -15.28% (p=0.000 n=10)
geomean                     26.94m         22.12m       -17.90%

                          │   old.txt    │               new.txt                │
                          │     B/op     │     B/op      vs base                │
GatewayAPItoXDS/small-10    507.2Ki ± 0%   492.9Ki ± 0%   -2.83% (p=0.000 n=10)
GatewayAPItoXDS/medium-10   2.545Mi ± 7%   1.954Mi ± 2%  -23.21% (p=0.000 n=10)
GatewayAPItoXDS/large-10    2.832Gi ± 0%   2.831Gi ± 0%        ~ (p=0.529 n=10)
geomean                     15.40Mi        13.97Mi        -9.31%

                          │   old.txt   │               new.txt               │
                          │  allocs/op  │  allocs/op   vs base                │
GatewayAPItoXDS/small-10    8.328k ± 0%   8.017k ± 0%   -3.73% (p=0.000 n=10)
GatewayAPItoXDS/medium-10   39.45k ± 6%   29.74k ± 2%  -24.60% (p=0.000 n=10)
GatewayAPItoXDS/large-10    38.75M ± 0%   38.71M ± 0%   -0.11% (p=0.000 n=10)
geomean                     233.5k        209.8k       -10.16%

Signed-off-by: Takeshi Yoneda <[email protected]>

* removes garbage

Signed-off-by: Takeshi Yoneda <[email protected]>

* more tests

Signed-off-by: Takeshi Yoneda <[email protected]>

* more tests

Signed-off-by: Takeshi Yoneda <[email protected]>

---------

Signed-off-by: Takeshi Yoneda <[email protected]>
zirain added a commit that referenced this pull request Sep 16, 2025
* fix: cluster stat name: lowercase Kind (#6780)

cluster stat name: lowercase Kind

Signed-off-by: Guy Daich <[email protected]>
Signed-off-by: zirain <[email protected]>

* fix: envoy service cluster name for zone-aware routing (#6763)

* fix!: fix envoy service cluster name for zone-aware routing

Signed-off-by: y-rabie <[email protected]>

* extend e2e tests for zone aware routing

Signed-off-by: y-rabie <[email protected]>

* extend unit tests for zone aware routing

Signed-off-by: y-rabie <[email protected]>

---------

Signed-off-by: y-rabie <[email protected]>
Signed-off-by: zirain <[email protected]>

* conformance: update experimental test report (#6782)

* conformance: update experimental test report

Signed-off-by: zirain <[email protected]>

* fix version

Signed-off-by: zirain <[email protected]>

* fix(api): image validation regex, support port in repository (#6819)

fix: match repository in image with port

Signed-off-by: Windfarer <[email protected]>
Signed-off-by: zirain <[email protected]>

* fix: Actually update xdsIR with maxAcceptPerSocketEvent (#6834)

* Actually update xdsIR with maxAcceptPerSocketEvent

Signed-off-by: jukie <[email protected]>

* release note

Signed-off-by: jukie <[email protected]>

* newline lint

Signed-off-by: jukie <[email protected]>

---------

Signed-off-by: jukie <[email protected]>
Signed-off-by: zirain <[email protected]>

* bugfix: fix the topologyInjectorDisabled and the local cluster was not defined (#6847)

* bugfix: fix the topologyInjectorDisabled and the local cluster was not defined.

Signed-off-by: qicz <[email protected]>

* fix ut

Signed-off-by: qicz <[email protected]>

* add topology-injector-enabled ut

Signed-off-by: qicz <[email protected]>

* add release note

Signed-off-by: qi <[email protected]>

---------

Signed-off-by: qicz <[email protected]>
Signed-off-by: qi <[email protected]>
Signed-off-by: zirain <[email protected]>

* fix(logging): correct log formatting to avoid DPANIC in controller-runtime logger (#6846)

* Update filters.go

Signed-off-by: TomerJLevy <[email protected]>

* add release notes

Signed-off-by: TomerJLevy <[email protected]>

---------

Signed-off-by: TomerJLevy <[email protected]>
Signed-off-by: zirain <[email protected]>

* fix: handle context errors as transient errors (#6850)

* handle context errors as transient errors

Signed-off-by: TomerJLevy <[email protected]>

* add test cases

Signed-off-by: TomerJLevy <[email protected]>

* no need the new line

Signed-off-by: TomerJLevy <[email protected]>

* add release notes

Signed-off-by: TomerJLevy <[email protected]>

* Return the error as is

Signed-off-by: TomerJLevy <[email protected]>

* revert redundant changes

Signed-off-by: TomerJLevy <[email protected]>

* revert unrelated changes

Signed-off-by: TomerJLevy <[email protected]>

* revert more changes...

Signed-off-by: TomerJLevy <[email protected]>

---------

Signed-off-by: TomerJLevy <[email protected]>
Co-authored-by: zirain <[email protected]>
Signed-off-by: zirain <[email protected]>

* bugfix: the controller cannot read the EnvoyProxy attached gatewayclass only. (#6838)

Signed-off-by: zirain <[email protected]>

* chore: fix CVE (#6903)

Signed-off-by: Shahar Harari <[email protected]>
Signed-off-by: zirain <[email protected]>

* fix: nil pointer dereference in btp configmap indexer (#6921)

Signed-off-by: Rudrakh Panigrahi <[email protected]>
Signed-off-by: zirain <[email protected]>

* improve targetRef selection for targetSelectors (#6917)

* improve targetRef selection for targetSelectors

* only select refs in the same namespace as the policy

Signed-off-by: Arko Dasgupta <[email protected]>

* fix lint

Signed-off-by: Arko Dasgupta <[email protected]>

---------

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* fix: suppress lua validation logs (#6929)

Signed-off-by: Rudrakh Panigrahi <[email protected]>
Signed-off-by: zirain <[email protected]>

* fix: rm incorrectly set exclusiveMaximum field in CRD (#6926)

* fix: rm incorrectly set exclusiveMaximum field in CRD

* Also fix maximum value to 599 which includes 599 as a valid num

Fixes: #6925

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* fix: rm Strict SameSite default (#6941)

* by default it should be unset which implies `Lax`

Relates to #6347

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* Optimize pod cache (#6936)

* Optimize pod cache

Signed-off-by: jukie <[email protected]>

* release note

Signed-off-by: jukie <[email protected]>

* Remove retry

Signed-off-by: jukie <[email protected]>

* cleanup

Signed-off-by: jukie <[email protected]>

---------

Signed-off-by: jukie <[email protected]>
Signed-off-by: Isaac <[email protected]>
Co-authored-by: zirain <[email protected]>
Signed-off-by: zirain <[email protected]>

* reduce DeepCopy in gateway-api layer (#6940)

* reduce deep copy in gateway-api layer

* also fixed the DeepCopy implementation for ControllerResources
which was performing a Shallow Copy resulting it lack of isolation
b/w provider and gateway-api layer

Relates to #6919

Signed-off-by: Arko Dasgupta <[email protected]>

* fix lint

Signed-off-by: Arko Dasgupta <[email protected]>

---------

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* fix: validation for grpc routes with extension ref filters (#6949)

Signed-off-by: Rudrakh Panigrahi <[email protected]>
Signed-off-by: zirain <[email protected]>

* fix: cleanup dangling route status conditions (#6812)

Signed-off-by: y-rabie <[email protected]>
Signed-off-by: zirain <[email protected]>

* Fix: Add missing patch annotations to Compression struct for proper Merge (#6951)

* fix: merge compression annotation

Signed-off-by: sudipto baral <[email protected]>

* test: add more compression merge test cases

Signed-off-by: sudipto baral <[email protected]>

---------

Signed-off-by: sudipto baral <[email protected]>
Signed-off-by: zirain <[email protected]>

* fix: update distroless image to resolve glibc CVEs (#6953)

Signed-off-by: Shahar Harari <[email protected]>
Signed-off-by: zirain <[email protected]>

* chore: bump golang to 1.24.7 (#6959)

chore: bump golang

Signed-off-by: zirain <[email protected]>

* fix: Make sure proxy protocol filter is the first listener filter (#6972)

Fixes: #6873

Signed-off-by: Arko Dasgupta <[email protected]>
Co-authored-by: Jacob Neil Taylor <[email protected]>
Signed-off-by: zirain <[email protected]>

* release notes

Signed-off-by: zirain <[email protected]>

* Removes reflection from RouteContext to reduce allocations (#6820)

* bench: adds APIToXDS bench & small opt

Signed-off-by: Takeshi Yoneda <[email protected]>

* no refect

goos: darwin
goarch: arm64
pkg: github.com/envoyproxy/gateway/test/gobench
cpu: Apple M1 Pro
                          │   old.txt    │               new.txt               │
                          │    sec/op    │   sec/op     vs base                │
GatewayAPItoXDS/small-10    881.2µ ±  7%   803.4µ ± 1%   -8.82% (p=0.000 n=10)
GatewayAPItoXDS/medium-10   4.130m ± 26%   2.959m ± 4%  -28.36% (p=0.000 n=10)
GatewayAPItoXDS/large-10     5.375 ±  2%    4.553 ± 1%  -15.28% (p=0.000 n=10)
geomean                     26.94m         22.12m       -17.90%

                          │   old.txt    │               new.txt                │
                          │     B/op     │     B/op      vs base                │
GatewayAPItoXDS/small-10    507.2Ki ± 0%   492.9Ki ± 0%   -2.83% (p=0.000 n=10)
GatewayAPItoXDS/medium-10   2.545Mi ± 7%   1.954Mi ± 2%  -23.21% (p=0.000 n=10)
GatewayAPItoXDS/large-10    2.832Gi ± 0%   2.831Gi ± 0%        ~ (p=0.529 n=10)
geomean                     15.40Mi        13.97Mi        -9.31%

                          │   old.txt   │               new.txt               │
                          │  allocs/op  │  allocs/op   vs base                │
GatewayAPItoXDS/small-10    8.328k ± 0%   8.017k ± 0%   -3.73% (p=0.000 n=10)
GatewayAPItoXDS/medium-10   39.45k ± 6%   29.74k ± 2%  -24.60% (p=0.000 n=10)
GatewayAPItoXDS/large-10    38.75M ± 0%   38.71M ± 0%   -0.11% (p=0.000 n=10)
geomean                     233.5k        209.8k       -10.16%

Signed-off-by: Takeshi Yoneda <[email protected]>

* removes garbage

Signed-off-by: Takeshi Yoneda <[email protected]>

* more tests

Signed-off-by: Takeshi Yoneda <[email protected]>

* more tests

Signed-off-by: Takeshi Yoneda <[email protected]>

---------

Signed-off-by: Takeshi Yoneda <[email protected]>

---------

Signed-off-by: Guy Daich <[email protected]>
Signed-off-by: zirain <[email protected]>
Signed-off-by: y-rabie <[email protected]>
Signed-off-by: Windfarer <[email protected]>
Signed-off-by: jukie <[email protected]>
Signed-off-by: qicz <[email protected]>
Signed-off-by: qi <[email protected]>
Signed-off-by: TomerJLevy <[email protected]>
Signed-off-by: Shahar Harari <[email protected]>
Signed-off-by: Rudrakh Panigrahi <[email protected]>
Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: Isaac <[email protected]>
Signed-off-by: sudipto baral <[email protected]>
Signed-off-by: Takeshi Yoneda <[email protected]>
Co-authored-by: Guy Daich <[email protected]>
Co-authored-by: Youssef Rabie <[email protected]>
Co-authored-by: Windfarer <[email protected]>
Co-authored-by: Isaac <[email protected]>
Co-authored-by: qi <[email protected]>
Co-authored-by: TomerJLevy <[email protected]>
Co-authored-by: shahar-h <[email protected]>
Co-authored-by: Rudrakh Panigrahi <[email protected]>
Co-authored-by: Arko Dasgupta <[email protected]>
Co-authored-by: Sudipto Baral <[email protected]>
Co-authored-by: Jacob Neil Taylor <[email protected]>
Co-authored-by: Takeshi Yoneda <[email protected]>
arkodg pushed a commit to arkodg/gateway that referenced this pull request Sep 19, 2025
* similar to envoyproxy#6820

```
  BenchmarkBackendRefContext_Old_HTTPBackendRef-12             	 5002508	       239.5 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_HTTPBackendRef-12             	 4764154	       264.1 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_HTTPBackendRef-12             	 4866708	       238.6 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_HTTPBackendRef-12             	 5032014	       243.8 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_HTTPBackendRef-12             	 4935594	       259.5 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_GRPCBackendRef-12             	 4833061	       245.3 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_GRPCBackendRef-12             	 4970496	       252.1 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_GRPCBackendRef-12             	 4517140	       253.2 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_GRPCBackendRef-12             	 4556660	       273.4 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_GRPCBackendRef-12             	 5003169	       244.2 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_New_HTTPBackendRef-12             	1000000000	         0.2556 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_HTTPBackendRef-12             	1000000000	         0.2495 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_HTTPBackendRef-12             	1000000000	         0.2499 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_HTTPBackendRef-12             	1000000000	         0.2576 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_HTTPBackendRef-12             	1000000000	         0.2556 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_GRPCBackendRef-12             	1000000000	         0.2505 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_GRPCBackendRef-12             	1000000000	         0.2504 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_GRPCBackendRef-12             	1000000000	         0.2591 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_GRPCBackendRef-12             	1000000000	         0.2502 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_GRPCBackendRef-12             	1000000000	         0.2483 ns/op	       0 B/op	       0 allocs/op
  ```

Signed-off-by: Arko Dasgupta <[email protected]>
rudrakhp pushed a commit that referenced this pull request Sep 20, 2025
* similar to #6820

```
  BenchmarkBackendRefContext_Old_HTTPBackendRef-12             	 5002508	       239.5 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_HTTPBackendRef-12             	 4764154	       264.1 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_HTTPBackendRef-12             	 4866708	       238.6 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_HTTPBackendRef-12             	 5032014	       243.8 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_HTTPBackendRef-12             	 4935594	       259.5 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_GRPCBackendRef-12             	 4833061	       245.3 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_GRPCBackendRef-12             	 4970496	       252.1 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_GRPCBackendRef-12             	 4517140	       253.2 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_GRPCBackendRef-12             	 4556660	       273.4 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_GRPCBackendRef-12             	 5003169	       244.2 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_New_HTTPBackendRef-12             	1000000000	         0.2556 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_HTTPBackendRef-12             	1000000000	         0.2495 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_HTTPBackendRef-12             	1000000000	         0.2499 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_HTTPBackendRef-12             	1000000000	         0.2576 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_HTTPBackendRef-12             	1000000000	         0.2556 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_GRPCBackendRef-12             	1000000000	         0.2505 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_GRPCBackendRef-12             	1000000000	         0.2504 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_GRPCBackendRef-12             	1000000000	         0.2591 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_GRPCBackendRef-12             	1000000000	         0.2502 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_GRPCBackendRef-12             	1000000000	         0.2483 ns/op	       0 B/op	       0 allocs/op
  ```

Signed-off-by: Arko Dasgupta <[email protected]>
zirain pushed a commit to zirain/gateway that referenced this pull request Oct 1, 2025
* similar to envoyproxy#6820

```
  BenchmarkBackendRefContext_Old_HTTPBackendRef-12             	 5002508	       239.5 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_HTTPBackendRef-12             	 4764154	       264.1 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_HTTPBackendRef-12             	 4866708	       238.6 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_HTTPBackendRef-12             	 5032014	       243.8 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_HTTPBackendRef-12             	 4935594	       259.5 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_GRPCBackendRef-12             	 4833061	       245.3 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_GRPCBackendRef-12             	 4970496	       252.1 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_GRPCBackendRef-12             	 4517140	       253.2 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_GRPCBackendRef-12             	 4556660	       273.4 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_GRPCBackendRef-12             	 5003169	       244.2 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_New_HTTPBackendRef-12             	1000000000	         0.2556 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_HTTPBackendRef-12             	1000000000	         0.2495 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_HTTPBackendRef-12             	1000000000	         0.2499 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_HTTPBackendRef-12             	1000000000	         0.2576 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_HTTPBackendRef-12             	1000000000	         0.2556 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_GRPCBackendRef-12             	1000000000	         0.2505 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_GRPCBackendRef-12             	1000000000	         0.2504 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_GRPCBackendRef-12             	1000000000	         0.2591 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_GRPCBackendRef-12             	1000000000	         0.2502 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_GRPCBackendRef-12             	1000000000	         0.2483 ns/op	       0 B/op	       0 allocs/op
  ```

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>
zirain added a commit that referenced this pull request Oct 3, 2025
* rm DeepCopy from Status Updator (#6986)

* Use Shallow Copy for TypedMeta, ObjectMeta and Spec
which are read only fields during the status update

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: avoid string concatenation overhead of fmt.Sprintf in Sort (#6987)

~14% improvement in CPU

```
 benchstat old.txt new.txt
goos: darwin
goarch: amd64
pkg: github.com/envoyproxy/gateway/test/gobench
cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
                          │   old.txt    │                new.txt                │
                          │    sec/op    │    sec/op     vs base                 │
GatewayAPItoXDS/small-12    4.257m ± ∞ ¹   2.707m ± ∞ ¹        ~ (p=0.700 n=3) ²
GatewayAPItoXDS/medium-12   37.32m ± ∞ ¹   34.76m ± ∞ ¹        ~ (p=1.000 n=3) ²
GatewayAPItoXDS/large-12    409.5m ± ∞ ¹   437.1m ± ∞ ¹        ~ (p=1.000 n=3) ²
geomean                     40.22m         34.52m        -14.17%
¹ need >= 6 samples for confidence interval at level 0.95
² need >= 4 samples to detect a difference at alpha level 0.05

                          │    old.txt    │                new.txt                │
                          │     B/op      │     B/op       vs base                │
GatewayAPItoXDS/small-12    721.7Ki ± ∞ ¹   722.4Ki ± ∞ ¹       ~ (p=0.700 n=3) ²
GatewayAPItoXDS/medium-12   15.63Mi ± ∞ ¹   15.63Mi ± ∞ ¹       ~ (p=0.100 n=3) ²
GatewayAPItoXDS/large-12    151.3Mi ± ∞ ¹   151.3Mi ± ∞ ¹       ~ (p=1.000 n=3) ²
geomean                     11.86Mi         11.86Mi        +0.04%
¹ need >= 6 samples for confidence interval at level 0.95
² need >= 4 samples to detect a difference at alpha level 0.05

                          │   old.txt    │               new.txt                │
                          │  allocs/op   │  allocs/op    vs base                │
GatewayAPItoXDS/small-12    11.70k ± ∞ ¹   11.71k ± ∞ ¹       ~ (p=0.700 n=3) ²
GatewayAPItoXDS/medium-12   257.3k ± ∞ ¹   257.3k ± ∞ ¹       ~ (p=0.700 n=3) ²
GatewayAPItoXDS/large-12    2.467M ± ∞ ¹   2.467M ± ∞ ¹       ~ (p=0.200 n=3) ²
geomean                     195.1k         195.2k        +0.03%
```

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: improve mem allocation in TruncatePolicyAncestors (#6998)

* perf: improve mem allocation in TruncatePolicyAncestors

Relates to #6919

Signed-off-by: Arko Dasgupta <[email protected]>

* lint

Signed-off-by: Arko Dasgupta <[email protected]>

* also sort on ns before name

Signed-off-by: Arko Dasgupta <[email protected]>

---------

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: reuse route rule metadata (#7001)

* perf: reuse route rule metadata

* build it once and pass it in the caller
* also since EG annotations are rare, make
sure to return early and reduce allocations

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: reduce mem allocs in internal/metrics (#7004)

```
                         │   old.txt    │       new.txt       │
                         │    sec/op    │    sec/op     vs base   │
  MergeLabelValuesOld-12   354.6n ± 42%
  MergeLabelValuesNew-12                  131.6n ± 18%

                         │  old.txt   │      new.txt      │
                         │    B/op    │    B/op     vs base   │
  MergeLabelValuesOld-12   640.0 ± 0%
  MergeLabelValuesNew-12                320.0 ± 0%

                         │  old.txt   │      new.txt      │
                         │ allocs/op  │ allocs/op   vs base   │
  MergeLabelValuesOld-12   2.000 ± 0%
  MergeLabelValuesNew-12                1.000 ± 0%
```

Signed-off-by: Arko Dasgupta <[email protected]>
Co-authored-by: Rudrakh Panigrahi <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: aggregate publish metric counts and call once (#7005)

* Reduces calls from O(N) where N is the total number of resources to O(1)

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: avoid loop variable in k8s provider (#7010)

* reduces heap allocs
* also removes the copyloopvar lint error

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: remove reflect from BackendRefContext (#7015)

* similar to #6820

```
  BenchmarkBackendRefContext_Old_HTTPBackendRef-12             	 5002508	       239.5 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_HTTPBackendRef-12             	 4764154	       264.1 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_HTTPBackendRef-12             	 4866708	       238.6 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_HTTPBackendRef-12             	 5032014	       243.8 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_HTTPBackendRef-12             	 4935594	       259.5 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_GRPCBackendRef-12             	 4833061	       245.3 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_GRPCBackendRef-12             	 4970496	       252.1 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_GRPCBackendRef-12             	 4517140	       253.2 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_GRPCBackendRef-12             	 4556660	       273.4 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_GRPCBackendRef-12             	 5003169	       244.2 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_New_HTTPBackendRef-12             	1000000000	         0.2556 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_HTTPBackendRef-12             	1000000000	         0.2495 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_HTTPBackendRef-12             	1000000000	         0.2499 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_HTTPBackendRef-12             	1000000000	         0.2576 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_HTTPBackendRef-12             	1000000000	         0.2556 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_GRPCBackendRef-12             	1000000000	         0.2505 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_GRPCBackendRef-12             	1000000000	         0.2504 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_GRPCBackendRef-12             	1000000000	         0.2591 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_GRPCBackendRef-12             	1000000000	         0.2502 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_GRPCBackendRef-12             	1000000000	         0.2483 ns/op	       0 B/op	       0 allocs/op
  ```

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* rm reflect from gateway api runner (#7012)

* use length check instead of a relfect
  `ValueOf(backend.Status).IsZero()` check

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: lazy allocation for new condition in SetConditionForPolicyAncestor (#6999)

* only create a new condition when we need to i.e. when it doesnt
  already exist

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* Fix weighted cluster generation in RouteAction when URLRewrite filter is applied (#7027)

* Fix weighted cluster generation in RouteAction when URLRewrite filter is applied

Signed-off-by: Sekar Saravanan <[email protected]>

* XDS translator test added - Fix weighted cluster generation in RouteAction when URLRewrite filter is applied

Signed-off-by: Sekar Saravanan <[email protected]>

---------

Signed-off-by: Sekar Saravanan <[email protected]>
Signed-off-by: zirain <[email protected]>

* fix: use SDS for service account token in Gateway Namespace Mode (#7002)

* use sds config for credential injector

Signed-off-by: Karol Szwaj <[email protected]>

* check for token review status error

Signed-off-by: Karol Szwaj <[email protected]>

* use sds config for credential injector

Signed-off-by: Karol Szwaj <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: reduce ancestorRef copies in policy status (#7032)

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: preallocate structs in securitypolicy processing (#7039)

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: remove reflect.DeepCopy in parentRef comparison (#7040)

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* fix: escape regex metacharacters from path prefix string (#7024)

Signed-off-by: Rudrakh Panigrahi <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: convert mockData into string and reuse in lua (#7078)

Signed-off-by: Arko Dasgupta <[email protected]>
Co-authored-by: Rudrakh Panigrahi <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: make sets when needed in policy processing (#7076)

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: preallocate slices in route processing (#7041)

* perf: preallocate slices in route processing

Signed-off-by: Arko Dasgupta <[email protected]>

* use index

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: enable gocritic perfomance linter setting (#7056)

https://go-critic.com/overview#checkers-from-the-performance-group

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: avoid JSON Marshal when debug logger is disabled (#7066)

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: avoid YAML to JSON conversion in JSONPatch (#7069)

* Use value.Raw directly

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* Fix: Preserve route parent status for multi-parent routes (#7068)

* fix: preserve route parent statuses during merge

Routes with multiple parent references should maintain status for all
parents, not just the one being currently updated. The mergeRouteParentStatus
function was incorrectly removing parent statuses when they weren't in the
current update batch.

This change preserves all existing parent statuses during the merge operation,
ensuring routes with multiple parents maintain status for all parent refs.

Fixes #7067

Signed-off-by: rajsinghtech <[email protected]>
Signed-off-by: Raj Singh <[email protected]>

* fix: remove unused controllerName parameter and update tests

- Remove unused controllerName parameter from mergeRouteParentStatus function
- Update test expectations to match the new behavior where all parent
  statuses are preserved during merge operations
- This ensures routes with multiple parent references maintain status
  for all parents, not just the ones being currently updated

Signed-off-by: rajsinghtech <[email protected]>
Signed-off-by: Raj Singh <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: remove watchable LoadAll() from gateway api runner (#7081)

* perf: remove watchable LoadAll() from gateway api runner

* use a keyCache in the gateway-api runner instead of
making an expensive LoadAll() call thats copies all the statuses and IRs
on every subscribe adding a ton of pressure for GC

* use the same mark and sweep operation to clean up the key cache and
  watchable store

* make a one time LoadAll() call in runner Start() to populate the cache
  for the restart runner case (when EnvoyGateway config is updated)

Signed-off-by: Arko Dasgupta <[email protected]>

* fix tests

Signed-off-by: Arko Dasgupta <[email protected]>

* fix test

Signed-off-by: Arko Dasgupta <[email protected]>

* rm populateCache, not needed

since we restart runners and reset watchable messages
https://github.com/envoyproxy/gateway/blob/d973842ea2f948a7d6eb2163e8ecc6950b49ae3d/internal/cmd/server.go#L65

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: enable prealloc linter (#7055)

* perf: enable prealloc linter

* and fix all the warnings

Fixes: #7053

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: pre allocate maps in btp processing (#7050)

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: fix possible memory leak in XDS snapshot (#7101)

perf: fix possible mem leak in XDS snapshot

Signed-off-by: Rudrakh Panigrahi <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: direct assign policies in translate result instead of append (#7077)

* perf: direct assign policies in translate result instead of append

Signed-off-by: Arko Dasgupta <[email protected]>

* fix test

Signed-off-by: Arko Dasgupta <[email protected]>

---------

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* remove redundant file

Signed-off-by: zirain <[email protected]>

* fix: do not add same service multiple times (#7119)

Signed-off-by: zirain <[email protected]>

* fix: use maps for backendRefMappings instead of Sets (#7120)

* fix: use maps for backendRefMappings instead of Sets

* Sets compare by value and BackendRef contain multiple ptrs to Kind,
  Group and Namespace, so this Set didnt really serve us any good
  purpose of deduping same backendRefs
* Instead use maps keyed by a util string - NamespaceNameWithGroupKind
similar to what we use for ExtentionRefFilters

Signed-off-by: Arko Dasgupta <[email protected]>

* make key a ptr

Signed-off-by: Arko Dasgupta <[email protected]>

* fix test

Signed-off-by: Arko Dasgupta <[email protected]>

---------

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* bug: disable x-envoy-ratelimited by default (#7110)

* bug: disable x-envoy-ratelimited by default

* can be enabled with `enableEnvoyHeaders` in CTP

Relates to #7034

Signed-off-by: Arko Dasgupta <[email protected]>

* fix tests and release note

Signed-off-by: Arko Dasgupta <[email protected]>

* fix testdata

Signed-off-by: Arko Dasgupta <[email protected]>

---------

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* fix: use lock when accessing mergeGateways Set (#7124)

* fix: use lock when accessing mergeGateways Set

* accessed in multiple goroutines to map proxy fleet to resource via
  labels

Fixes this panic

```
fatal error: concurrent map read and map write

   4 internal/runtime/maps.fatal({0x3b83570?, 0x8b3de58?})
   5     /opt/hostedtoolcache/go/1.24.7/x64/src/runtime/panic.go:1058 +0x18
   6 k8s.io/apimachinery/pkg/util/sets.Set[...[].Has(...)
   7     /home/runner/go/pkg/mod/k8s.io/[email protected]/pkg/util/sets/set.go:78
   8 github.com/envoyproxy/gateway/internal/provider/kubernetes.(*gatewayAPIReconciler).envoyObjectForGateway.func1({0x8bc2dc8, 0xc0054163f0})
   9     /home/runner/work/gateway/gateway/internal/provider/kubernetes/predicates.go:666 +0x7b
  10 github.com/envoyproxy/gateway/internal/provider/kubernetes.(*gatewayAPIReconciler).envoyObjectForGateway(0xc0018858e8?, {0x8ba6648?, 0xc0009c8b90?}, 0x11?)
  11     /home/runner/work/gateway/gateway/internal/provider/kubernetes/predicates.go:682 +0x5e
  12 github.com/envoyproxy/gateway/internal/provider/kubernetes.(*gatewayAPIReconciler).updateStatusForGateway(0xc000516600, {0x8ba6648, 0xc0009c8b90}, 0xc00541a380)
  13     /home/runner/work/gateway/gateway/internal/provider/kubernetes/status.go:579 +0x5a
  14 github.com/envoyproxy/gateway/internal/provider/kubernetes.(*gatewayAPIReconciler).subscribeAndUpdateStatus.func2.1({{{0xc0096a7e46, 0x7}, {0xc001944cc0, 0x11}}, 0x0, 0xc0052fa690}, 0xc00a582a1     0)
```

Relates to #7115 (comment)

Signed-off-by: Arko Dasgupta <[email protected]>

* lint

Signed-off-by: Arko Dasgupta <[email protected]>

---------

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

---------

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>
Signed-off-by: Sekar Saravanan <[email protected]>
Signed-off-by: Karol Szwaj <[email protected]>
Signed-off-by: Rudrakh Panigrahi <[email protected]>
Signed-off-by: rajsinghtech <[email protected]>
Signed-off-by: Raj Singh <[email protected]>
Co-authored-by: Arko Dasgupta <[email protected]>
Co-authored-by: Rudrakh Panigrahi <[email protected]>
Co-authored-by: sekar-saravanan <[email protected]>
Co-authored-by: Karol Szwaj <[email protected]>
Co-authored-by: Raj Singh <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants