Reuse native checkpoints before source length changes
This commit is contained in:
1 parent
465a574124
commit
6acd82dbfa
8 files changed
+222
-4
No files matched your search
@@ -366,8 +366,8 @@ impl EntryCheckpoint {
|
||||
&& self.executor.sources[self.entry].name == earlier.executor.sources[earlier.entry].name
|
||||
&& self.source_mouth(self.entry)
|
||||
.same_loaded_prefix_constraint(earlier.source_mouth(earlier.entry))
|
||||
&& (!self.executor.reads.observed_statistics()
|
||||
|| (earlier.executor.reads.observed_statistics()
|
||||
&& (self.can_resize_entry()
|
||||
|| (!earlier.can_resize_entry()
|
||||
&& self.executor.sources[self.entry].data.len()
|
||||
== earlier.executor.sources[earlier.entry].data.len()))
|
||||
}
|
||||
@@ -380,7 +380,20 @@ impl EntryCheckpoint {
|
||||
let entry = &self.executor.sources[self.entry];
|
||||
// A suspended scanner may only accept unchanged bytes when its
|
||||
// boundary cannot be authenticated as a physical line.
|
||||
entry.name == name && (entry.data == data || self.matches_scanned_source(self.entry, data))
|
||||
entry.name == name
|
||||
&& (entry.data == data
|
||||
|| ((entry.data.len() == data.len() || self.can_resize_entry())
|
||||
&& self.source_mouth(self.entry).matches_loaded_prefix(data)))
|
||||
}
|
||||
|
||||
fn can_resize_entry(&self) -> bool {
|
||||
// At each retained shipout, the original entry is still the bottom
|
||||
// source frame. Reject ambiguous accounting if it also opened as
|
||||
// another source before this checkpoint.
|
||||
!self.executor.reads.observed_statistics()
|
||||
|| self.executor.sources.iter().filter(|source| {
|
||||
source.name == self.executor.sources[self.entry].name
|
||||
}).take(2).count() == 1
|
||||
}
|
||||
|
||||
pub fn entry_frontier(&self) -> usize {
|
||||
@@ -487,6 +500,14 @@ impl EntryCheckpoint {
|
||||
}
|
||||
let mut executor = self.executor.clone().with_cancellation(cancellation);
|
||||
executor.line_break_cache = line_break_cache;
|
||||
let previous_len = self.executor.sources[self.entry].data.len();
|
||||
let current_len = source.data.len();
|
||||
if previous_len != current_len
|
||||
&& self.executor.reads.observed_statistics()
|
||||
&& executor.resize_entry_statistics(previous_len, current_len, files.replayed_entry_bytes()).is_none()
|
||||
{
|
||||
return Ok(None);
|
||||
}
|
||||
executor.rebind_checkpoint_source(self.entry, source);
|
||||
if let Some(nested) = nested {
|
||||
executor.rebind_checkpoint_source(self.active_source, nested);
|
||||
|
||||
@@ -181,6 +181,24 @@ impl Executor {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn resize_entry_statistics(
|
||||
&mut self,
|
||||
previous: usize,
|
||||
current: usize,
|
||||
replayed_entry_bytes: Option<u64>,
|
||||
) -> Option<()> {
|
||||
let events = self.events.prefix.iter_mut()
|
||||
.filter(|chunk| chunk.iter().any(|event| matches!(event, Event::Statistics(_))))
|
||||
.flat_map(|chunk| Arc::make_mut(chunk).iter_mut())
|
||||
.chain(&mut self.events.tail);
|
||||
for event in events {
|
||||
if let Event::Statistics(report) = event {
|
||||
report.resize_entry_payload(previous, current, replayed_entry_bytes)?;
|
||||
}
|
||||
}
|
||||
Some(())
|
||||
}
|
||||
|
||||
pub(super) fn equivalent_accounting_history(&self, old: &Self) -> bool {
|
||||
// These containers may reintroduce previously retained allocations
|
||||
// that are outside the accounting walk at this boundary.
|
||||
|
||||
@@ -376,6 +376,11 @@ pub trait SourceProvider {
|
||||
) -> Result<(), String> {
|
||||
Ok(())
|
||||
}
|
||||
/// Size of the entry read already validated by the host's prefix replay.
|
||||
/// Hosts that report resource telemetry can opt in to resizing that read.
|
||||
fn replayed_entry_bytes(&self) -> Option<u64> {
|
||||
None
|
||||
}
|
||||
/// Observe resource accounting while preserving the typed report for replay.
|
||||
fn observe_statistics(&mut self, report: &StatisticsReport) -> Result<(), String> {
|
||||
self.observe_diagnostic(report.destination, &report.text)
|
||||
|
||||
@@ -81,6 +81,11 @@ pub struct HostResourceUsage {
|
||||
pub open_outputs: Option<usize>,
|
||||
}
|
||||
impl HostResourceUsage {
|
||||
pub fn rebind_entry_bytes(&mut self, previous: u64, current: u64) -> Option<()> {
|
||||
self.resource_bytes_read = self.resource_bytes_read.checked_sub(previous)?.checked_add(current)?;
|
||||
Some(())
|
||||
}
|
||||
|
||||
pub fn from_trace(trace: &crate::resources::ResourceTrace) -> Self {
|
||||
Self {
|
||||
lookups: trace.lookups.len(),
|
||||
@@ -172,6 +177,32 @@ impl StatisticsReport {
|
||||
Self { phase, destination, text, span }
|
||||
}
|
||||
|
||||
pub(super) fn resize_entry_payload(
|
||||
&mut self,
|
||||
previous: usize,
|
||||
current: usize,
|
||||
replayed_entry_bytes: Option<u64>,
|
||||
) -> Option<()> {
|
||||
// Closeout reports are produced only after resuming, never captured
|
||||
// in an executable prefix. Shipout text does not print byte totals.
|
||||
let StatisticsPhase::Shipout { before, after } = &mut self.phase else {
|
||||
return None;
|
||||
};
|
||||
for usage in [before, after] {
|
||||
usage.source_payload_bytes = usage.source_payload_bytes.checked_sub(previous)?.checked_add(current)?;
|
||||
usage.mouth_payload_bytes = usage.mouth_payload_bytes.checked_sub(previous)?.checked_add(current)?;
|
||||
if let Some(host) = &mut usage.host {
|
||||
let size = u64::try_from(current).ok()?;
|
||||
if replayed_entry_bytes != Some(size) {
|
||||
return None;
|
||||
}
|
||||
host.rebind_entry_bytes(u64::try_from(previous).ok()?, size)?;
|
||||
}
|
||||
}
|
||||
debug_assert_eq!(self.text, self.phase.text());
|
||||
Some(())
|
||||
}
|
||||
|
||||
pub fn with_step_offset(&self, offset: StepOffset) -> Option<Self> {
|
||||
let mut phase = self.phase.clone();
|
||||
match &mut phase {
|
||||
|
||||
Reference in new issue
Block a user