Skip to content

Commit 14ae8c6

Browse files
committed
Encode None into ShallowUpdate
This shrinks the return value from 16 to 8 bytes
1 parent 22bef96 commit 14ae8c6

File tree

2 files changed

+48
-34
lines changed

2 files changed

+48
-34
lines changed

src/function/fetch.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ where
7575

7676
let database_key_index = self.database_key_index(id);
7777

78-
let shallow_update = self.shallow_verify_memo(zalsa, database_key_index, memo)?;
78+
let can_shallow_update = self.shallow_verify_memo(zalsa, database_key_index, memo);
7979

80-
if !memo.may_be_provisional() {
81-
self.update_shallow(zalsa, database_key_index, memo, shallow_update);
80+
if can_shallow_update.yes() && !memo.may_be_provisional() {
81+
self.update_shallow(zalsa, database_key_index, memo, can_shallow_update);
8282

8383
// SAFETY: memo is present in memo_map and we have verified that it is
8484
// still valid for the current revision.
@@ -109,10 +109,15 @@ where
109109
if memo.value.is_some()
110110
&& memo.revisions.cycle_heads.contains(&database_key_index)
111111
{
112-
if let Some(shallow_update) =
113-
self.shallow_verify_memo(zalsa, database_key_index, memo)
114-
{
115-
self.update_shallow(zalsa, database_key_index, memo, shallow_update);
112+
let can_shallow_update =
113+
self.shallow_verify_memo(zalsa, database_key_index, memo);
114+
if can_shallow_update.yes() {
115+
self.update_shallow(
116+
zalsa,
117+
database_key_index,
118+
memo,
119+
can_shallow_update,
120+
);
116121
// SAFETY: memo is present in memo_map.
117122
return unsafe { Some(self.extend_memo_lifetime(memo)) };
118123
}

src/function/maybe_changed_after.rs

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,18 @@ where
9090
return VerifyResult::changed();
9191
};
9292

93-
if let Some(shallow_update) = self.shallow_verify_memo(zalsa, database_key_index, memo)
94-
{
95-
if !memo.may_be_provisional() {
96-
self.update_shallow(zalsa, database_key_index, memo, shallow_update);
97-
98-
return if memo.revisions.changed_at > revision {
99-
VerifyResult::changed()
100-
} else {
101-
VerifyResult::Unchanged(
102-
memo.revisions.accumulated_inputs.load(),
103-
CycleHeads::default(),
104-
)
105-
};
106-
}
93+
let can_shallow_update = self.shallow_verify_memo(zalsa, database_key_index, memo);
94+
if can_shallow_update.yes() && !memo.may_be_provisional() {
95+
self.update_shallow(zalsa, database_key_index, memo, can_shallow_update);
96+
97+
return if memo.revisions.changed_at > revision {
98+
VerifyResult::changed()
99+
} else {
100+
VerifyResult::Unchanged(
101+
memo.revisions.accumulated_inputs.load(),
102+
CycleHeads::default(),
103+
)
104+
};
107105
}
108106

109107
if let Some(mcs) = self.maybe_changed_after_cold(
@@ -228,7 +226,7 @@ where
228226
zalsa: &Zalsa,
229227
database_key_index: DatabaseKeyIndex,
230228
memo: &Memo<C::Output<'_>>,
231-
) -> Option<ShallowUpdate> {
229+
) -> ShallowUpdate {
232230
tracing::debug!(
233231
"{database_key_index:?}: shallow_verify_memo(memo = {memo:#?})",
234232
memo = memo.tracing_debug()
@@ -238,7 +236,7 @@ where
238236

239237
if verified_at == revision_now {
240238
// Already verified.
241-
return Some(ShallowUpdate::Verified);
239+
return ShallowUpdate::Verified;
242240
}
243241

244242
let last_changed = zalsa.last_changed_revision(memo.revisions.durability);
@@ -251,9 +249,9 @@ where
251249
);
252250
if last_changed <= verified_at {
253251
// No input of the suitable durability has changed since last verified.
254-
Some(ShallowUpdate::HigherDurability(revision_now))
252+
ShallowUpdate::HigherDurability(revision_now)
255253
} else {
256-
None
254+
ShallowUpdate::No
257255
}
258256
}
259257

@@ -383,19 +381,18 @@ where
383381
old_memo = old_memo.tracing_debug()
384382
);
385383

386-
let shallow_update = self.shallow_verify_memo(zalsa, database_key_index, old_memo);
387-
let shallow_update_possible = shallow_update.is_some();
388-
if let Some(shallow_update) = shallow_update {
389-
if self.validate_may_be_provisional(
384+
let can_shallow_update = self.shallow_verify_memo(zalsa, database_key_index, old_memo);
385+
if can_shallow_update.yes()
386+
&& self.validate_may_be_provisional(
390387
zalsa,
391388
db.zalsa_local(),
392389
database_key_index,
393390
old_memo,
394-
) {
395-
self.update_shallow(zalsa, database_key_index, old_memo, shallow_update);
391+
)
392+
{
393+
self.update_shallow(zalsa, database_key_index, old_memo, can_shallow_update);
396394

397-
return VerifyResult::unchanged();
398-
}
395+
return VerifyResult::unchanged();
399396
}
400397

401398
match &old_memo.revisions.origin {
@@ -430,7 +427,7 @@ where
430427

431428
// If the value is from the same revision but is still provisional, consider it changed
432429
// because we're now in a new iteration.
433-
if shallow_update_possible && is_provisional {
430+
if can_shallow_update.yes() && is_provisional {
434431
return VerifyResult::changed();
435432
}
436433

@@ -550,4 +547,16 @@ pub(super) enum ShallowUpdate {
550547
/// The revision for the memo's durability hasn't changed. It can be marked as verified
551548
/// in this revision.
552549
HigherDurability(Revision),
550+
551+
/// The memo requires a deep verification.
552+
No,
553+
}
554+
555+
impl ShallowUpdate {
556+
pub(super) fn yes(&self) -> bool {
557+
matches!(
558+
self,
559+
ShallowUpdate::Verified | ShallowUpdate::HigherDurability(_)
560+
)
561+
}
553562
}

0 commit comments

Comments
 (0)