Skip to content

reduce DeepCopy in gateway-api layer#6940

Merged
zirain merged 2 commits intoenvoyproxy:mainfrom
arkodg:reduce-deepCopy-gwawpi
Sep 12, 2025
Merged

reduce DeepCopy in gateway-api layer#6940
zirain merged 2 commits intoenvoyproxy:mainfrom
arkodg:reduce-deepCopy-gwawpi

Conversation

@arkodg
Copy link
Copy Markdown
Contributor

@arkodg arkodg commented Sep 11, 2025

 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    3.852m ± ∞ ¹   2.691m ± ∞ ¹        ~ (p=0.700 n=3) ²
GatewayAPItoXDS/medium-12   51.09m ± ∞ ¹   43.25m ± ∞ ¹        ~ (p=0.700 n=3) ²
GatewayAPItoXDS/large-12    397.4m ± ∞ ¹   385.0m ± ∞ ¹        ~ (p=0.700 n=3) ²
geomean                     42.76m         35.52m        -16.94%
¹ 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    727.2Ki ± ∞ ¹   723.0Ki ± ∞ ¹       ~ (p=0.400 n=3) ²
GatewayAPItoXDS/medium-12   15.90Mi ± ∞ ¹   15.63Mi ± ∞ ¹       ~ (p=0.100 n=3) ²
GatewayAPItoXDS/large-12    153.9Mi ± ∞ ¹   151.3Mi ± ∞ ¹       ~ (p=0.100 n=3) ²
geomean                     12.02Mi         11.86Mi        -1.31%
¹ 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.80k ± ∞ ¹   11.72k ± ∞ ¹       ~ (p=0.400 n=3) ²
GatewayAPItoXDS/medium-12   261.3k ± ∞ ¹   257.3k ± ∞ ¹       ~ (p=0.100 n=3) ²
GatewayAPItoXDS/large-12    2.505M ± ∞ ¹   2.467M ± ∞ ¹       ~ (p=0.100 n=3) ²
geomean                     197.7k         195.2k        -1.26%
¹ need >= 6 samples for confidence interval at level 0.95
² need >= 4 samples to detect a difference at alpha level 0.05

  • 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

@arkodg arkodg requested a review from a team as a code owner September 11, 2025 02:06
@arkodg arkodg marked this pull request as draft September 11, 2025 02:06
@arkodg arkodg changed the title reduce deep copy in gateway-api layer reduce DeepCopy in gateway-api layer Sep 11, 2025
@arkodg arkodg force-pushed the reduce-deepCopy-gwawpi branch from 32f2a9c to c62b833 Compare September 11, 2025 04:05
@arkodg arkodg marked this pull request as ready for review September 11, 2025 04:05
@arkodg arkodg requested review from a team and mathetake September 11, 2025 04:06
@zirain zirain force-pushed the reduce-deepCopy-gwawpi branch from c62b833 to 636d203 Compare September 11, 2025 04:21
@codecov
Copy link
Copy Markdown

codecov bot commented Sep 11, 2025

Codecov Report

❌ Patch coverage is 96.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 71.02%. Comparing base (53c24c8) to head (e4a08a4).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
internal/gatewayapi/backendtrafficpolicy.go 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6940      +/-   ##
==========================================
- Coverage   71.03%   71.02%   -0.02%     
==========================================
  Files         226      226              
  Lines       40037    40038       +1     
==========================================
- Hits        28441    28436       -5     
- Misses       9915     9921       +6     
  Partials     1681     1681              

☔ 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.

Xunzhuo
Xunzhuo previously approved these changes Sep 11, 2025
Copy link
Copy Markdown
Member

@Xunzhuo Xunzhuo left a comment

Choose a reason for hiding this comment

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

Nice hacking

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Curious why needed a DeepCopy before, and why even do the shallow copy now? Are we modifying policy during the process?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

looks like its been there from the beginning
we dont need a deepCopy here because the gateway-api layer is free to update the object received from watchable and modify it, which it does ( modifies status)
note, there was a bug in DeepCopy implementation of ControllerResources that I fixed in this PR too which was keeping some shallow copy references around, that was needed to be changed to a pure DeepCopy for isolation between the provider layer and gateway-api layer

Copy link
Copy Markdown
Member

@rudrakhp rudrakhp Sep 12, 2025

Choose a reason for hiding this comment

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

the gateway-api layer is free to update the object received from watchable and modify it

Why not use currPolicy everywhere in that case? Can we remove the shallow copy policy = currPolicy? Unless this is intentional to avoid multiple changes. Approved as this is minor.

Copy link
Copy Markdown
Contributor Author

@arkodg arkodg Sep 12, 2025

Choose a reason for hiding this comment

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

Sure will try doing another round of clean up

@arkodg arkodg marked this pull request as draft September 11, 2025 16:15
@arkodg arkodg force-pushed the reduce-deepCopy-gwawpi branch 2 times, most recently from 451f781 to 89b997e Compare September 11, 2025 18:54
@arkodg arkodg marked this pull request as ready for review September 11, 2025 19:10
@arkodg arkodg force-pushed the reduce-deepCopy-gwawpi branch from df57c90 to ad483f1 Compare September 11, 2025 20:08
@arkodg arkodg requested review from Xunzhuo and rudrakhp September 11, 2025 20:21
Arko Dasgupta added 2 commits September 12, 2025 17:14
* 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 envoyproxy#6919

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: Arko Dasgupta <[email protected]>
@zirain zirain force-pushed the reduce-deepCopy-gwawpi branch from ad483f1 to e4a08a4 Compare September 12, 2025 09:14
@zirain zirain enabled auto-merge (squash) September 12, 2025 09:14
@zirain
Copy link
Copy Markdown
Member

zirain commented Sep 12, 2025

/retest

@zirain zirain merged commit 106dba3 into envoyproxy:main Sep 12, 2025
51 of 53 checks passed
@arkodg arkodg deleted the reduce-deepCopy-gwawpi branch September 15, 2025 03:56
zirain pushed a commit to zirain/gateway that referenced this pull request Sep 16, 2025
* 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 envoyproxy#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]>
zirain pushed a commit to zirain/gateway that referenced this pull request Sep 16, 2025
* 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 envoyproxy#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]>
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]>
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.

5 participants