@@ -777,23 +777,49 @@ final class RouteManager: ObservableObject {
777777 var newRoutes : [ ActiveRoute ] = [ ]
778778 var failedCount = 0
779779
780- // Apply domain routes
780+ // Collect all domains to resolve (for parallel resolution)
781+ var allDomains : [ ( domain: String , source: String ) ] = [ ]
782+
783+ // Add custom domains
781784 for domain in config. domains where domain. enabled {
782- if let routes = await applyRoutesForDomain ( domain. domain, gateway: gateway) {
785+ allDomains. append ( ( domain. domain, domain. domain) )
786+ }
787+
788+ // Add service domains
789+ for service in config. services where service. enabled {
790+ for domain in service. domains {
791+ allDomains. append ( ( domain, service. name) )
792+ }
793+ }
794+
795+ // Resolve domains in parallel (much faster than sequential)
796+ log ( . info, " Resolving \( allDomains. count) domains... " )
797+
798+ let routeResults = await withTaskGroup ( of: [ ActiveRoute] ? . self, returning: [ [ ActiveRoute ] ? ] . self) { group in
799+ for item in allDomains {
800+ group. addTask {
801+ await self . applyRoutesForDomain ( item. domain, gateway: gateway, source: item. source)
802+ }
803+ }
804+
805+ var results : [ [ ActiveRoute ] ? ] = [ ]
806+ for await result in group {
807+ results. append ( result)
808+ }
809+ return results
810+ }
811+
812+ // Collect results
813+ for result in routeResults {
814+ if let routes = result {
783815 newRoutes. append ( contentsOf: routes)
784816 } else {
785817 failedCount += 1
786818 }
787819 }
788820
789- // Apply service routes
821+ // Apply IP ranges (these don't need DNS resolution)
790822 for service in config. services where service. enabled {
791- for domain in service. domains {
792- if let routes = await applyRoutesForDomain ( domain, gateway: gateway, source: service. name) {
793- newRoutes. append ( contentsOf: routes)
794- }
795- }
796- // Apply IP ranges
797823 for range in service. ipRanges {
798824 if await applyRouteForRange ( range, gateway: gateway) {
799825 newRoutes. append ( ActiveRoute (
0 commit comments