Skip to content

meshcontroller: improve service instance search performance in Master#1503

Merged
xxx7xxxx merged 2 commits intoeasegress-io:mainfrom
LokiWager:improve-service-instance-search-performance-11165963452841478242
Mar 7, 2026
Merged

meshcontroller: improve service instance search performance in Master#1503
xxx7xxxx merged 2 commits intoeasegress-io:mainfrom
LokiWager:improve-service-instance-search-performance-11165963452841478242

Conversation

@LokiWager
Copy link
Copy Markdown
Collaborator

Replaced the O(N*M) nested loop in checkServiceInstances with an O(N+M) map-based lookup. This significantly improves performance when dealing with a large number of service instances.

The map uses a composite key consisting of ServiceName and InstanceID to uniquely identify each instance status.

Replaced the O(N*M) nested loop in checkServiceInstances with an
O(N+M) map-based lookup. This significantly improves performance
when dealing with a large number of service instances.

The map uses a composite key consisting of ServiceName and InstanceID
to uniquely identify each instance status.

Co-authored-by: LokiWager <32408858+LokiWager@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

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

Improves Master.checkServiceInstances performance by replacing an O(N*M) nested search with an O(N+M) map lookup keyed by (ServiceName, InstanceID).

Changes:

  • Build a map of service instance statuses keyed by service name + instance ID
  • Replace per-spec linear scan with a direct map lookup

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}
statusMap := make(map[instanceKey]*spec.ServiceInstanceStatus)
for _, s := range statuses {
statusMap[instanceKey{s.ServiceName, s.InstanceID}] = s
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

The composite key literals rely on positional field order, which is easy to accidentally swap later. Prefer keyed struct literals for clarity and safety (e.g., instanceKey{serviceName: ..., instanceID: ...}).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

status = s
}
}
status := statusMap[instanceKey{_spec.ServiceName, _spec.InstanceID}]
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

The composite key literals rely on positional field order, which is easy to accidentally swap later. Prefer keyed struct literals for clarity and safety (e.g., instanceKey{serviceName: ..., instanceID: ...}).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@LokiWager LokiWager marked this pull request as draft March 3, 2026 15:57
@LokiWager LokiWager marked this pull request as ready for review March 3, 2026 15:58
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 3, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 0% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 37.63%. Comparing base (f9117fa) to head (ac6e9cc).
⚠️ Report is 64 commits behind head on main.

Files with missing lines Patch % Lines
pkg/object/meshcontroller/master/master.go 0.00% 9 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

❗ There is a different number of reports uploaded between BASE (f9117fa) and HEAD (ac6e9cc). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (f9117fa) HEAD (ac6e9cc)
2 1
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1503       +/-   ##
===========================================
- Coverage   79.48%   37.63%   -41.85%     
===========================================
  Files         152      374      +222     
  Lines       17295    41858    +24563     
===========================================
+ Hits        13747    15754     +2007     
- Misses       2879    25235    +22356     
- Partials      669      869      +200     

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

@xxx7xxxx
Copy link
Copy Markdown
Contributor

xxx7xxxx commented Mar 7, 2026

@copilot add a commit to fix your reviewing suggestion

@xxx7xxxx xxx7xxxx added this pull request to the merge queue Mar 7, 2026
Merged via the queue into easegress-io:main with commit 80d6d73 Mar 7, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants