@@ -641,7 +641,7 @@ pub trait IsStarkProver<
641641 air_trace_pairs : & [ AirTracePair < ' _ , Field , FieldExtension , PI > ] ,
642642 metadatas : & [ Round1Metadata < Field , FieldExtension > ] ,
643643 domains : & [ Domain < Field > ] ,
644- twiddle_caches : & [ LdeTwiddles < Field > ] ,
644+ twiddle_caches : & [ Arc < LdeTwiddles < Field > > ] ,
645645 main_pool : & mut [ Vec < FieldElement < Field > > ] ,
646646 aux_pool : & mut [ Vec < FieldElement < FieldExtension > > ] ,
647647 ) where
@@ -657,7 +657,13 @@ pub trait IsStarkProver<
657657 . zip ( domains. iter ( ) . zip ( twiddle_caches. iter ( ) ) )
658658 {
659659 let result = Self :: reconstruct_round1 (
660- * air, * trace, domain, metadata, twiddles, main_pool, aux_pool,
660+ * air,
661+ * trace,
662+ domain,
663+ metadata,
664+ & * * twiddles,
665+ main_pool,
666+ aux_pool,
661667 )
662668 . expect ( "reconstruct_round1 failed in debug-checks" ) ;
663669 temp_results. push ( result) ;
@@ -1518,20 +1524,28 @@ pub trait IsStarkProver<
15181524 let phase_start = Instant :: now ( ) ;
15191525
15201526 let mut domains = Vec :: with_capacity ( num_airs) ;
1521- let mut twiddle_caches: Vec < LdeTwiddles < Field > > = Vec :: with_capacity ( num_airs) ;
1527+ let mut twiddle_caches: Vec < Arc < LdeTwiddles < Field > > > = Vec :: with_capacity ( num_airs) ;
15221528 let mut max_main_cols = 0usize ;
15231529 let mut max_aux_cols = 0usize ;
15241530
1531+ // Deduplicate twiddle caches: tables with the same lde_size share one Arc.
1532+ let mut twiddle_by_size: std:: collections:: HashMap < usize , Arc < LdeTwiddles < Field > > > =
1533+ std:: collections:: HashMap :: new ( ) ;
1534+
15251535 for ( air, trace, _pub_inputs) in & * air_trace_pairs {
15261536 let trace_length = trace. num_rows ( ) ;
15271537 let domain = new_domain ( * air, trace_length) ;
1528- let twiddles = LdeTwiddles :: new ( & domain) ;
1538+
1539+ let lde_size = domain. interpolation_domain_size * domain. blowup_factor ;
1540+ let twiddles = twiddle_by_size
1541+ . entry ( lde_size)
1542+ . or_insert_with ( || Arc :: new ( LdeTwiddles :: new ( & domain) ) ) ;
15291543
15301544 max_main_cols = max_main_cols. max ( trace. num_main_columns ) ;
15311545 max_aux_cols = max_aux_cols. max ( air. num_auxiliary_rap_columns ( ) ) ;
15321546
15331547 domains. push ( domain) ;
1534- twiddle_caches. push ( twiddles) ;
1548+ twiddle_caches. push ( Arc :: clone ( twiddles) ) ;
15351549 }
15361550
15371551 // Allocate K independent LDE column buffer pool sets for parallel table processing.
@@ -1573,7 +1587,7 @@ pub trait IsStarkProver<
15731587 let idx = chunk_start + j;
15741588 let ( air, trace, _) = & air_trace_pairs[ idx] ;
15751589 let domain = & domains[ idx] ;
1576- let twiddles = & twiddle_caches[ idx] ;
1590+ let twiddles = & * twiddle_caches[ idx] ;
15771591
15781592 let result = if air. is_preprocessed ( ) {
15791593 Self :: commit_preprocessed_trace (
@@ -1705,7 +1719,7 @@ pub trait IsStarkProver<
17051719 let idx = chunk_start + j;
17061720 let ( air, trace, _) = & air_trace_pairs[ idx] ;
17071721 let domain = & domains[ idx] ;
1708- let twiddles = & twiddle_caches[ idx] ;
1722+ let twiddles = & * twiddle_caches[ idx] ;
17091723
17101724 if air. has_aux_trace ( ) {
17111725 let num_aux_cols = trace. num_aux_columns ;
0 commit comments