Deterministic Replay

THotPDF.DeterministicReplayLog captures external decisions that can make an operation behave differently across runs, then substitutes the recorded results during replay

Captured decisions

Record and replay

var
  ReplayJSON: AnsiString;
begin
  PDF.DeterministicReplayLog.BeginRecording;
  PDF.ReadProgressiveLinearizedFirstPageSection(Source, Output, Info);
  ReplayJSON := PDF.DeterministicReplayLog.ExportJSON;

  PDF.DeterministicReplayLog.ImportJSON(ReplayJSON);
  PDF.ReadProgressiveLinearizedFirstPageSection(Source, Output, Info);
  if not PDF.DeterministicReplayLog.CompleteReplay then
    raise Exception.Create(PDF.DeterministicReplayLog.LastDiagnostic);
end;

Ordering and validation

Every event carries a monotonic sequence number, event kind, name, two signed 64-bit arguments, and a typed result

Replay consumes events in order and validates their complete signature before returning the recorded result; strict mode raises EHPDFDeterministicReplayMismatch on exhaustion or divergence, while non-strict mode retains a mismatch count and diagnostic and uses the observed result

CompleteReplay succeeds only after every retained event has been consumed without mismatches or dropped recording events

Bounds and performance

EventLimit defaults to 100,000 events, DroppedEventCount reports overflow, and event storage grows geometrically so append cost remains amortised constant time

The JSON schema is hotpdf-deterministic-replay-v1; 64-bit arguments and integer results are encoded as decimal strings to preserve exact values across JSON implementations

Related APIs