Reuse settled suffixes after verified closed child edits

This commit is contained in:
gloamxun committed 2026-12-02 01:53:20 +08:00
1 parent 55c497dccd
commit e4d6e049f8
11 files changed
+565 -72

No files matched your search

@@ -1,7 +1,7 @@
use super::super::statistics::{
Collector,
Ownership::{Active, Retained},
RetainedHistoryOffset,
RetainedHistoryOffset, SuffixSourceResize,
};
use super::*;
impl Executor {
@@ -232,16 +232,16 @@ impl Executor {
}
pub(super) fn equivalent_accounting_history(&self, old: &Self) -> bool {
self.equivalent_accounting_history_with_entry_sizes(old, None)
self.equivalent_accounting_history_with_source_resize(old, None)
}
pub(super) fn equivalent_accounting_history_with_entry_sizes(
pub(super) fn equivalent_accounting_history_with_source_resize(
&self,
old: &Self,
entry_sizes: Option<(usize, usize)>,
resize: Option<SuffixSourceResize>,
) -> bool {
[Collector::for_capacity, Collector::default].into_iter().all(|collector| {
self.collect_compared_accounting(old, entry_sizes, collector).is_some_and(
self.collect_compared_accounting(old, resize, collector).is_some_and(
|(live, old_live, history, old_history)| {
live.has_equivalent_history(&old_live, &history, &old_history)
},
@@ -252,17 +252,17 @@ impl Executor {
pub(super) fn retained_history_offset(
&self,
old: &Self,
entry_sizes: Option<(usize, usize)>,
resize: Option<SuffixSourceResize>,
) -> Option<RetainedHistoryOffset> {
let (live, old_live, history, old_history) =
self.collect_compared_accounting(old, entry_sizes, Collector::default)?;
self.collect_compared_accounting(old, resize, Collector::default)?;
live.retained_history_offset(&old_live, &history, &old_history)
}
fn collect_compared_accounting(
&self,
old: &Self,
entry_sizes: Option<(usize, usize)>,
resize: Option<SuffixSourceResize>,
collector: fn() -> Collector,
) -> Option<(Collector, Collector, Collector, Collector)> {
// These containers may reintroduce previously retained allocations
@@ -284,10 +284,13 @@ impl Executor {
// The splice translates the cumulative counters separately.
live.usage.steps = old_live.usage.steps;
live.usage.box_nodes_created = old_live.usage.box_nodes_created;
if let Some((previous, current)) = entry_sizes {
if let Some(resize) = resize {
let (previous, current) = resize.sizes;
let restore = |bytes: usize| bytes.checked_sub(current)?.checked_add(previous);
live.usage.source_payload_bytes = restore(live.usage.source_payload_bytes)?;
live.usage.mouth_payload_bytes = restore(live.usage.mouth_payload_bytes)?;
if resize.active_at_anchor {
live.usage.mouth_payload_bytes = restore(live.usage.mouth_payload_bytes)?;
}
}
Some((live, old_live, history, old_history))
}