File tree 5 files changed +32
-13
lines changed
5 files changed +32
-13
lines changed Original file line number Diff line number Diff line change @@ -172,7 +172,10 @@ impl ActiveQuery {
172
172
. is_empty ( )
173
173
. not ( )
174
174
. then ( || Box :: new ( mem:: take ( accumulated) ) ) ;
175
- let tracked_struct_ids = mem:: take ( tracked_struct_ids) ;
175
+ let tracked_struct_ids = tracked_struct_ids
176
+ . is_empty ( )
177
+ . not ( )
178
+ . then ( || Box :: new ( mem:: take ( tracked_struct_ids) ) ) ;
176
179
let accumulated_inputs = AtomicInputAccumulatedValues :: new ( accumulated_inputs) ;
177
180
let cycle_heads = mem:: take ( cycle_heads) ;
178
181
QueryRevisions {
Original file line number Diff line number Diff line change @@ -27,19 +27,23 @@ where
27
27
) {
28
28
// Iterate over the outputs of the `old_memo` and put them into a hashset
29
29
let mut old_outputs: FxHashSet < _ > = old_memo. revisions . origin . outputs ( ) . collect ( ) ;
30
-
31
30
// Iterate over the outputs of the current query
32
31
// and remove elements from `old_outputs` when we find them
33
32
for new_output in revisions. origin . outputs ( ) {
34
33
old_outputs. remove ( & new_output) ;
35
34
}
36
35
37
- if !old_outputs. is_empty ( ) {
38
- // Remove the outputs that are no longer present in the current revision
39
- // to prevent that the next revision is seeded with a id mapping that no longer exists.
40
- revisions. tracked_struct_ids . retain ( |& k, & mut value| {
41
- !old_outputs. contains ( & DatabaseKeyIndex :: new ( k. ingredient_index ( ) , value) )
42
- } ) ;
36
+ if let Some ( tracked_struct_ids) = & mut revisions. tracked_struct_ids {
37
+ if !old_outputs. is_empty ( ) {
38
+ // Remove the outputs that are no longer present in the current revision
39
+ // to prevent that the next revision is seeded with a id mapping that no longer exists.
40
+ tracked_struct_ids. retain ( |& k, & mut value| {
41
+ !old_outputs. contains ( & DatabaseKeyIndex :: new ( k. ingredient_index ( ) , value) )
42
+ } ) ;
43
+ }
44
+ if tracked_struct_ids. is_empty ( ) {
45
+ revisions. tracked_struct_ids = None ;
46
+ }
43
47
}
44
48
45
49
for old_output in old_outputs {
Original file line number Diff line number Diff line change 1
1
use crate :: {
2
2
cycle:: { CycleRecoveryStrategy , MAX_ITERATIONS } ,
3
3
zalsa:: ZalsaDatabase ,
4
- zalsa_local:: ActiveQueryGuard ,
4
+ zalsa_local:: { ActiveQueryGuard , QueryRevisions } ,
5
5
Database , Event , EventKind ,
6
6
} ;
7
7
52
52
loop {
53
53
// If we already executed this query once, then use the tracked-struct ids from the
54
54
// previous execution as the starting point for the new one.
55
- if let Some ( old_memo) = opt_old_memo {
56
- active_query. seed_tracked_struct_ids ( & old_memo. revisions . tracked_struct_ids ) ;
55
+ if let Some ( Memo {
56
+ revisions :
57
+ QueryRevisions {
58
+ tracked_struct_ids : Some ( tracked_struct_ids) ,
59
+ ..
60
+ } ,
61
+ ..
62
+ } ) = opt_old_memo
63
+ {
64
+ active_query. seed_tracked_struct_ids ( tracked_struct_ids) ;
57
65
}
58
66
59
67
// Query was not previously executed, or value is potentially
Original file line number Diff line number Diff line change @@ -143,7 +143,7 @@ pub(super) struct Memo<V> {
143
143
// Memo's are stored a lot, make sure their size is doesn't randomly increase.
144
144
// #[cfg(test)]
145
145
const _: [ ( ) ; std:: mem:: size_of :: < Memo < std:: num:: NonZeroUsize > > ( ) ] =
146
- [ ( ) ; std:: mem:: size_of :: < [ usize ; 14 ] > ( ) ] ;
146
+ [ ( ) ; std:: mem:: size_of :: < [ usize ; 11 ] > ( ) ] ;
147
147
148
148
impl < V > Memo < V > {
149
149
pub ( super ) fn new ( value : Option < V > , revision_now : Revision , revisions : QueryRevisions ) -> Self {
Original file line number Diff line number Diff line change @@ -309,7 +309,11 @@ pub(crate) struct QueryRevisions {
309
309
/// previous revision. To handle this, `diff_outputs` compares
310
310
/// the structs from the old/new revision and retains
311
311
/// only entries that appeared in the new revision.
312
- pub ( super ) tracked_struct_ids : IdentityMap ,
312
+ ///
313
+ /// Since not all queries produce a tracked struct, wrapping
314
+ /// `IdentityMap` in an `Option<Box<T>>` reduces the size of
315
+ /// `QueryRevisions` by 3 words (24 bytes on a 64-bit platform).
316
+ pub ( super ) tracked_struct_ids : Option < Box < IdentityMap > > ,
313
317
314
318
pub ( super ) accumulated : Option < Box < AccumulatedMap > > ,
315
319
You can’t perform that action at this time.
0 commit comments