From dfadaab2152243c86694c06e36fdeb5ef0fce155 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Wed, 26 Feb 2025 09:53:22 -0700 Subject: [PATCH] shaping: micro-optimize get_egress_path_config impl w/ providers We make two passes over the provider data; the first to get the base provider stuff which can theoretically match multiple provider records, then a second to apply provider-source data over the top of that. That second pass should ideally hit the DNS cache for any of the providers that we checked in the first pass, but it is theoretically possible for entries to be pushed out of the cache or expire in the intervening time. Let's just keep a local note of what we want to include to avoid that possibility; it also shaves off some micro cpu overhead to decide what should apply. --- crates/kumo-api-types/src/shaping.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/crates/kumo-api-types/src/shaping.rs b/crates/kumo-api-types/src/shaping.rs index 7c65aa9b..523c3169 100644 --- a/crates/kumo-api-types/src/shaping.rs +++ b/crates/kumo-api-types/src/shaping.rs @@ -289,23 +289,27 @@ impl ShapingInner { // TSA http "domain name" here let is_domain_name = dns_resolver::Name::from_str_relaxed(domain).is_ok(); if is_domain_name { + let mut prov_with_sources = vec![]; + for prov in self.by_provider.values() { if prov.domain_matches(domain).await { toml_table_merge_from(&mut params.params, &prov.params); prov.apply_provider_params_to(egress_source, &mut params.params); + + if !prov.sources.is_empty() { + // Remember this matching provider, so that we + // can apply any source rules after we've applied + // any/all base provider rules for this domain + prov_with_sources.push(prov); + } } } // Then Provider source rules - for prov in self.by_provider.values() { - if prov.sources.is_empty() { - continue; - } - if prov.domain_matches(domain).await { - if let Some(source) = prov.sources.get(egress_source) { - toml_table_merge_from(&mut params.params, &source); - prov.apply_provider_params_to(egress_source, &mut params.params); - } + for prov in prov_with_sources { + if let Some(source) = prov.sources.get(egress_source) { + toml_table_merge_from(&mut params.params, &source); + prov.apply_provider_params_to(egress_source, &mut params.params); } } }