← Back to Docs

Lazy Loading Patterns

Defer non-critical work until it is actually needed — keep your loader lean and your payload invisible.

Why Lazy Load

Every millisecond spent initialising code the user does not yet need is a millisecond added to your detection window. Lazy loading lets you ship a minimal bootstrap that defers heavyweight subsystems — network probes, integrity scans, UI rendering — until a trigger fires.

Trigger Types

  • Time-based — stagger initialisation across a jittered window after process start.
  • Event-based — hook window creation, first mouse move, or first network activity.
  • Demand-based — resolve a stub only when a protected feature is actually invoked.

Implementation Sketch

// Bootstrap — runs immediately
void Bootstrap() {
  InitMinimalRuntime();
  RegisterDelayedWork(PhaseOne, 2000 + Jitter(800));
}

// Deferred phase
void PhaseOne() {
  if (!IsSafeEnvironment()) return;
  LoadIntegrityModule();
  RegisterDelayedWork(PhaseTwo, 5000 + Jitter(1200));
}

Each phase checks environmental safety before committing more code into memory. If the coast is not clear, the chain stops.

Pitfalls

  • Lazy-loaded modules still need their own integrity verification before execution.
  • Staggered loads create predictable memory-allocation patterns — randomise timing with cryptographic jitter.
  • A watchdog that never fires is dead code; every deferred unit must have a bounded deadline.