Reduce allocations in app server watcher#61985
Merged
rosstimothy merged 1 commit intomasterfrom Dec 4, 2025
Merged
Conversation
tigrato
reviewed
Dec 4, 2025
lib/srv/app/watcher.go
Outdated
| select { | ||
| case apps := <-watcher.ResourcesC: | ||
| appsWithAddr := make(types.Apps, 0, len(apps)) | ||
| appsWithAddr := apps[:0] |
Contributor
There was a problem hiding this comment.
is there a reason why you don't change apps slice in place?
nothing here skips the append to appsWithAddr, so you can just range the apps and set the public address without having to append anything or am I missing something?
Contributor
Author
There was a problem hiding this comment.
Good call. I've updated this in af6aa44 and updated the watcher tests to validate the public address is set accordingly.
tigrato
approved these changes
Dec 4, 2025
nicholasmarais1158
approved these changes
Dec 4, 2025
Contributor
nicholasmarais1158
left a comment
There was a problem hiding this comment.
Code looks good.
The slice of resources receivied from the watcher contains a copy of all the items known by the watcher. The app server then cloned each app via types.Application.Copy to get a handle to a types.AppV3 so that the public address could be set if it was empty. The cloned apps are then added to a _new_ slice which is provided to the reconciler. To reduce memory consumption, types.Application.SetPublicAddr was added to make it possible to set the address without copying an app. The slice from the resource watcher is now reused instead of allocating a new slice for the amended applications.
af6aa44 to
2a1f9fd
Compare
Contributor
|
@rosstimothy See the table below for backport results.
|
This was referenced Dec 4, 2025
21KennethTran
pushed a commit
that referenced
this pull request
Jan 6, 2026
The slice of resources receivied from the watcher contains a copy of all the items known by the watcher. The app server then cloned each app via types.Application.Copy to get a handle to a types.AppV3 so that the public address could be set if it was empty. The cloned apps are then added to a _new_ slice which is provided to the reconciler. To reduce memory consumption, types.Application.SetPublicAddr was added to make it possible to set the address without copying an app. The slice from the resource watcher is now reused instead of allocating a new slice for the amended applications.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The slice of resources received from the watcher contains a copy of all the items known by the watcher. The app server then cloned each app via types.Application.Copy to get a handle to a types.AppV3 so that the public address could be set if it was empty. The cloned apps are then added to a new slice which is provided to the reconciler.
To reduce memory consumption, types.Application.SetPublicAddr was added to make it possible to set the address without copying an app. The slice from the resource watcher is now reused instead of allocating a new slice for the amended applications.
changelog: Reduced memory consumption of the Application service.