⚡ perf(doctor): optimize port matrix conflict check loop - #410
Conversation
- 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)
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
💡 What:
Optimized the port matrix conflict checking loop in
server_manager::core::doctor::check_port_conflicts.HashSetcapacity based on the total count of service port definitions (HashSet::with_capacity(total_ports)).port.host_ip.clone()(Option<String>) withport.host_ip.as_deref()(Option<&str>).doctor_check_port_conflictsinbenches/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 dynamicHashSetre-hashes as capacity expanded from default initial sizes.📊 Measured Improvement:
Benchmarked using Criterion (
cargo bench --bench service_benchmark -- doctor_check_port_conflicts):PR created automatically by Jules for task 13098466155646316055 started by @Cylae