@@ -204,50 +204,55 @@ static SYMPY: std::sync::LazyLock<Benchmark<'static>> = std::sync::LazyLock::new
204204 )
205205} ) ;
206206
207- #[ bench ( args= [ & * ALTAIR , & * FREQTRADE , & * PYDANTIC ] , sample_size= 2 , sample_count= 3 ) ]
208- fn small ( bencher : Bencher , benchmark : & Benchmark ) {
207+ #[ track_caller ]
208+ fn run_single_threaded ( bencher : Bencher , benchmark : & Benchmark ) {
209209 bencher
210210 . with_inputs ( || benchmark. setup_iteration ( ) )
211211 . bench_local_refs ( |db| {
212212 check_project ( db, benchmark. max_diagnostics ) ;
213213 } ) ;
214214}
215215
216+ #[ bench( args=[ & * ALTAIR , & * FREQTRADE , & * PYDANTIC ] , sample_size=2 , sample_count=3 ) ]
217+ fn small ( bencher : Bencher , benchmark : & Benchmark ) {
218+ run_single_threaded ( bencher, benchmark) ;
219+ }
220+
216221#[ bench( args=[ & * COLOUR_SCIENCE , & * PANDAS ] , sample_size=1 , sample_count=3 ) ]
217222fn medium ( bencher : Bencher , benchmark : & Benchmark ) {
218- bencher
219- . with_inputs ( || benchmark. setup_iteration ( ) )
220- . bench_local_refs ( |db| {
221- check_project ( db, benchmark. max_diagnostics ) ;
222- } ) ;
223+ run_single_threaded ( bencher, benchmark) ;
223224}
224225
225226#[ bench( args=[ & * SYMPY ] , sample_size=1 , sample_count=2 ) ]
226227fn large ( bencher : Bencher , benchmark : & Benchmark ) {
228+ run_single_threaded ( bencher, benchmark) ;
229+ }
230+
231+ #[ bench( args=[ & * PYDANTIC ] , sample_size=3 , sample_count=3 ) ]
232+ fn multithreaded ( bencher : Bencher , benchmark : & Benchmark ) {
233+ let thread_pool = ThreadPoolBuilder :: new ( ) . build ( ) . unwrap ( ) ;
234+
227235 bencher
228236 . with_inputs ( || benchmark. setup_iteration ( ) )
229- . bench_local_refs ( |db| {
230- check_project ( db, benchmark. max_diagnostics ) ;
237+ . bench_local_values ( |db| {
238+ thread_pool. install ( || {
239+ check_project ( & db, benchmark. max_diagnostics ) ;
240+ db
241+ } )
231242 } ) ;
232243}
233244
234245fn main ( ) {
235- let filter =
236- std:: env:: var ( "TY_LOG" ) . unwrap_or ( "ty_walltime=info,ruff_benchmark=info" . to_string ( ) ) ;
237-
238- let _logging = setup_logging_with_filter ( & filter) . expect ( "Filter to be valid" ) ;
239-
240- // Disable multithreading for now due to
241- // https://github.com/salsa-rs/salsa/issues/918.
242- //
243- // Salsa has a fast-path for the first db when looking up ingredients.
244- // It seems that this fast-path becomes extremely slow for all db's other
245- // than the first one, especially when using multithreading (10x slower than the first run).
246246 ThreadPoolBuilder :: new ( )
247247 . num_threads ( 1 )
248248 . use_current_thread ( )
249249 . build_global ( )
250250 . unwrap ( ) ;
251251
252+ let filter =
253+ std:: env:: var ( "TY_LOG" ) . unwrap_or ( "ty_walltime=info,ruff_benchmark=info" . to_string ( ) ) ;
254+
255+ let _logging = setup_logging_with_filter ( & filter) . expect ( "Filter to be valid" ) ;
256+
252257 divan:: main ( ) ;
253258}
0 commit comments