diff --git a/server_manager/benches/service_benchmark.rs b/server_manager/benches/service_benchmark.rs index 46a961c..5944a1d 100644 --- a/server_manager/benches/service_benchmark.rs +++ b/server_manager/benches/service_benchmark.rs @@ -107,11 +107,21 @@ fn benchmark_port_matrix_generation(c: &mut Criterion) { }); } +fn benchmark_doctor_check_port_conflicts(c: &mut Criterion) { + c.bench_function("doctor_check_port_conflicts", |b| { + b.iter(|| { + let result = server_manager::core::doctor::check_port_conflicts(); + criterion::black_box(result); + }) + }); +} + criterion_group!( benches, benchmark_catalog_retrieval, benchmark_compose_generation, benchmark_validation_throughput, - benchmark_port_matrix_generation + benchmark_port_matrix_generation, + benchmark_doctor_check_port_conflicts ); criterion_main!(benches); diff --git a/server_manager/src/core/doctor.rs b/server_manager/src/core/doctor.rs index 2ed6fa5..5b85965 100644 --- a/server_manager/src/core/doctor.rs +++ b/server_manager/src/core/doctor.rs @@ -301,16 +301,13 @@ pub fn check_firewall() -> DoctorCheckResult { pub fn check_port_conflicts() -> DoctorCheckResult { let catalog = crate::services::get_service_catalog(); - let mut total_ports = 0; - for entry in &catalog { - total_ports += entry.ports.len(); - } + let total_ports: usize = catalog.iter().map(|entry| entry.ports.len()).sum(); // In a diagnostic check, we verify that the port matrix has zero internal collisions - let mut seen = std::collections::HashSet::new(); + let mut seen = std::collections::HashSet::with_capacity(total_ports); for entry in &catalog { for port in &entry.ports { - let key = (port.host_ip.clone(), port.host_port, port.protocol); + let key = (port.host_ip.as_deref(), port.host_port, port.protocol); if !seen.insert(key) { return DoctorCheckResult { name: "Port Matrix".to_string(),