Skip to content

Make backends a pointer to avoid copies #11490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

howardjohn
Copy link
Contributor

Description

Reduce memory allocations by using pointers to large backend objects. This object is very frequently copied around and is large, resulting in substantial allocation pressure. See pprof -- the big chunk at the left is entirely removed with this change (note: the pprof is obscure due to generics, I promise it is from BackendObjectIR 🙂 )

2025-06-25_17-37-20

Change Type

/kind cleanup

Changelog

NONE

Additional Notes

@Copilot Copilot AI review requested due to automatic review settings June 26, 2025 14:03
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR changes the handling of backend objects by switching from passing large BackendObjectIR values to pointers in order to reduce memory allocations.

  • Updated function signatures in the translator and policy index to accept pointers.
  • Adjusted lambda conversions and collection types accordingly.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
internal/kgateway/translator/irtranslator/backend.go Changed method signature and related backend handling to pointers.
internal/kgateway/proxy_syncer/status.go Modified generatePolicyReport to work with pointer types.
internal/kgateway/proxy_syncer/backends.go Updated collection lambda to process backend pointers.
internal/kgateway/krtcollections/policy.go Modified backend collections to use pointers and updated conversion.

@github-actions github-actions bot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. release-note-none labels Jun 26, 2025
@shashankram
Copy link
Contributor

Failing test and needs DCO

 Error: internal/kgateway/translator/irtranslator/backend_test.go:42:43: cannot use backend (variable of struct type "github.com/kgateway-dev/kgateway/v2/internal/kgateway/ir".BackendObjectIR) as *"github.com/kgateway-dev/kgateway/v2/internal/kgateway/ir".BackendObjectIR value in argument to bt.TranslateBackend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. release-note-none
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants