@@ -19,7 +19,7 @@ pub mod path_transform;
19
19
pub mod search;
20
20
pub mod rename;
21
21
22
- use std:: { fmt, sync:: Arc } ;
22
+ use std:: { fmt, mem :: ManuallyDrop , sync:: Arc } ;
23
23
24
24
use base_db:: {
25
25
salsa:: { self , Durability } ,
@@ -44,7 +44,19 @@ pub use base_db;
44
44
hir:: db:: HirDatabaseStorage
45
45
) ]
46
46
pub struct RootDatabase {
47
- storage : salsa:: Storage < RootDatabase > ,
47
+ // We use `ManuallyDrop` here because every codegen unit that contains a
48
+ // `&RootDatabase -> &dyn OtherDatabase` cast will instantiate its drop glue in the vtable,
49
+ // which duplicates `Weak::drop` and `Arc::drop` tens of thousands of times, which makes
50
+ // compile times of all `ide_*` and downstream crates suffer greatly.
51
+ storage : ManuallyDrop < salsa:: Storage < RootDatabase > > ,
52
+ }
53
+
54
+ impl Drop for RootDatabase {
55
+ fn drop ( & mut self ) {
56
+ unsafe {
57
+ ManuallyDrop :: drop ( & mut self . storage ) ;
58
+ }
59
+ }
48
60
}
49
61
50
62
impl fmt:: Debug for RootDatabase {
@@ -93,7 +105,7 @@ impl Default for RootDatabase {
93
105
94
106
impl RootDatabase {
95
107
pub fn new ( lru_capacity : Option < usize > ) -> RootDatabase {
96
- let mut db = RootDatabase { storage : salsa:: Storage :: default ( ) } ;
108
+ let mut db = RootDatabase { storage : ManuallyDrop :: new ( salsa:: Storage :: default ( ) ) } ;
97
109
db. set_crate_graph_with_durability ( Default :: default ( ) , Durability :: HIGH ) ;
98
110
db. set_local_roots_with_durability ( Default :: default ( ) , Durability :: HIGH ) ;
99
111
db. set_library_roots_with_durability ( Default :: default ( ) , Durability :: HIGH ) ;
@@ -112,7 +124,7 @@ impl RootDatabase {
112
124
113
125
impl salsa:: ParallelDatabase for RootDatabase {
114
126
fn snapshot ( & self ) -> salsa:: Snapshot < RootDatabase > {
115
- salsa:: Snapshot :: new ( RootDatabase { storage : self . storage . snapshot ( ) } )
127
+ salsa:: Snapshot :: new ( RootDatabase { storage : ManuallyDrop :: new ( self . storage . snapshot ( ) ) } )
116
128
}
117
129
}
118
130
0 commit comments