Skip to content

⚡ perf(doctor): optimize port matrix conflict check loop - #410

Open
Cylae wants to merge 1 commit into
mainfrom
perf/optimize-doctor-port-conflicts-13098466155646316055
Open

⚡ perf(doctor): optimize port matrix conflict check loop#410
Cylae wants to merge 1 commit into
mainfrom
perf/optimize-doctor-port-conflicts-13098466155646316055

Conversation

@Cylae

@Cylae Cylae commented Sep 9, 2026

Copy link
Copy Markdown
Owner

💡 What:

Optimized the port matrix conflict checking loop in server_manager::core::doctor::check_port_conflicts.

  • Pre-allocated HashSet capacity based on the total count of service port definitions (HashSet::with_capacity(total_ports)).
  • Eliminated per-iteration heap allocations by replacing port.host_ip.clone() (Option<String>) with port.host_ip.as_deref() (Option<&str>).
  • Added a Criterion benchmark function doctor_check_port_conflicts in benches/service_benchmark.rs.

🎯 Why:

In the original code, checking for port conflicts in the service catalog iterated through all services and ports while cloning port.host_ip (Option<String>) on every inner iteration to construct the lookup key (Option<String>, u16, Protocol). This caused repeated heap allocations and dynamic HashSet re-hashes as capacity expanded from default initial sizes.

📊 Measured Improvement:

Benchmarked using Criterion (cargo bench --bench service_benchmark -- doctor_check_port_conflicts):

  • Baseline runtime: 16.456 µs
  • Optimized runtime: 11.155 µs
  • Change: -32.27% (32.27% speedup, statistical significance p < 0.05)

PR created automatically by Jules for task 13098466155646316055 started by @Cylae

- Pre-allocate HashSet capacity based on catalog port count
- Replace string cloning with borrowed slices (as_deref) in HashSet lookup keys to eliminate per-iteration heap allocations
- Add Criterion benchmark for check_port_conflicts showing ~32.3% runtime reduction (16.46 µs -> 11.16 µs)
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

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.

1 participant