@@ -61,10 +61,8 @@ pub fn build_graph(
6161 thread_handles. push ( handle) ;
6262
6363 // Thread pool: Parse imports
64- let num_workers = thread:: available_parallelism ( )
65- . map ( |n| max ( n. get ( ) / 2 , 1 ) )
66- . unwrap_or ( 4 ) ;
67- for _ in 0 ..num_workers {
64+ let num_threads = num_threads_for_module_parsing ( ) ;
65+ for _ in 0 ..num_threads {
6866 let receiver = found_module_receiver. clone ( ) ;
6967 let sender = parsed_module_sender. clone ( ) ;
7068 let error_sender = error_sender. clone ( ) ;
@@ -142,10 +140,7 @@ struct ParsedModule {
142140}
143141
144142fn discover_python_modules ( package : & PackageSpec , sender : channel:: Sender < FoundModule > ) {
145- let num_threads = thread:: available_parallelism ( )
146- . map ( |n| max ( n. get ( ) / 2 , 1 ) )
147- . unwrap_or ( 4 ) ;
148-
143+ let num_threads = num_threads_for_module_discovery ( ) ;
149144 let package_clone = package. clone ( ) ;
150145
151146 WalkBuilder :: new ( & package. directory )
@@ -325,3 +320,19 @@ fn assemble_graph(
325320
326321 graph
327322}
323+
324+ /// Calculate the number of threads to use for module discovery.
325+ /// Uses half of available parallelism, with a minimum of 1 and default of 4.
326+ fn num_threads_for_module_discovery ( ) -> usize {
327+ thread:: available_parallelism ( )
328+ . map ( |n| max ( n. get ( ) / 2 , 1 ) )
329+ . unwrap_or ( 4 )
330+ }
331+
332+ /// Calculate the number of threads to use for module parsing.
333+ /// Uses half of available parallelism, with a minimum of 1 and default of 4.
334+ fn num_threads_for_module_parsing ( ) -> usize {
335+ thread:: available_parallelism ( )
336+ . map ( |n| max ( n. get ( ) / 2 , 1 ) )
337+ . unwrap_or ( 4 )
338+ }
0 commit comments