Xenon 2

Autopilot · write-up

Direct shared script bodies and dispatch bypass

xenondoc/AUTOPILOT_DIRECT_SCRIPT_BODIES.MD · 5 KB · updated 2026-09-17

Baseline: 74d1d6ee. This change uses the existing ABI-14 C body/candidate APIs; no C arithmetic, ABI change, or native rebuild is needed.

Removed work

Some independent scripted hazards already had native point paths, but still entered Python collision dispatch for every required frame. native_script_bodies.py now adds eligible paths directly to the native body scene. Collision and combat borrow the same pool and target indices; C computes the swept constant hull from consecutive anchors. The existing death-aware candidate evaluation still controls destruction.

Admission uses the authoritative collision dispatcher once. Only its generic hull branch marks a script root as eligible; the new code does not duplicate animation or special collision rules. Safety envelopes, special eye/shell bodies, linked models, pending spawns, unknown kinds, and wall-shot callbacks retain their existing handling. Dependent aimed shots remain in their separate prediction pass.

Non-script objects now bypass shared-script lookup in anchor, hazard-step and displacement requests. Eye and formation overrides still run first. The Python kernel and previous native preparation paths remain available.

Independent controls

  • c-slices-old: previous body slices and script dispatch.
  • c-slices-direct: direct native script bodies only.
  • c-slices-dispatch: non-script dispatch bypass only.
  • c: both enabled.

Use these with compare_kernels.py --variants ... --repeats 2 --pin-cpu. The implementation flags are shared_prediction_scene.DIRECT_BODIES and shared_prediction_scene.SKIP_NON_SCRIPTS. Replay/live diagnostics include native_script_body_paths; the existing slice counters show removed preparation.

Validation

The full suite passes 903 tests. New tests compare native contact and clearance with Python, verify that admitted objects no longer produce frame slices, retain special or linked/shot sources, and check that non-script queries avoid shared dispatch.

Unprofiled measurements

Two fresh pinned Level 1 runs per variant, with reverse order on the second repeat:

Variant Run 1 mean ms Run 2 mean ms Average mean ms
Previous preparation 4.303 4.291 4.297
Direct native bodies only 4.155 4.148 4.151
Non-script bypass only 4.304 4.296 4.300
Both changes 4.139 4.207 4.173

Direct bodies save 3.4% on their own. The dispatch bypass has no measurable standalone timing benefit in these runs. Combined processing is 2.9% faster, about 0.123 ms per observation. The combined repeats differ by 1.6%; differences this small between direct-only and combined cannot establish a dispatch regression or speedup. Do not add the independently measured percentages.

There are no changed verdicts across all 7,693 Level 1 observations (5,425 gameplay frames): action, tactic, movement authority, clearance, contact, predicted kills and pickups match. Per gameplay frame, native script-body admission adds 0.457 bodies on average. Remaining Python slice bodies fall from 0.712 to 0.254, and body-slice output falls from 1,664 to 435 bytes (74% less). Combat bound output falls from 2,436 to 2,113 bytes (13% less). This measures generated geometry, not peak memory or a new copy of the shared point pool.

Single old/new comparisons on the other available recordings also match all verdicts. These are cross-level checks, not repeated estimates of small speedups:

Recording Previous mean ms Both changes mean ms
Level 2 6.821 6.673
Level 3 9.537 8.929
Level 4 7.223 7.031
Level 5 2.848 2.748

These are sequential desktop replay timings without drawing, emulator execution, sockets, or WASM. No fresh live level completion is implied.

Separate profiling

All four instrumented variants also retain identical verdicts. These cumulative profile times overlap and are not additional unprofiled speedup measurements:

Measurement Previous Direct bodies only Bypass only Both
Total recorded function calls 162,112,544 154,116,929 161,179,986 153,184,371
Shared script requests 723,922 565,588 257,643 99,309
Hazard-step requests 393,604 232,789 393,604 232,789
Body frame-slice preparation, cumulative s 4.862 1.947 4.749 1.907

The dispatch bypass independently removes 466,279 unnecessary script requests, although the unprofiled total remains unchanged within measurement variation. Both changes remove about 8.93 million recorded calls. Body frame-slice preparation still receives the same number of frame requests, but most now return an empty slice range or prepare only the remaining specialized geometry. Native path admission costs 0.121 cumulative seconds including its one-time geometry probes.

Artifacts

  • xenon_tools/run_logs/direct-script-timing-0907/comparison.json: four-way, two-repeat unprofiled stage isolation.
  • xenon_tools/run_logs/direct-script-level*-0907/comparison.json: Level 2-5 old/new verdict checks.
  • xenon_tools/run_logs/direct-script-profile-0907/: separate instrumented runs.
  • xenon_tools/run_logs/direct-script-tests-0907.txt: full test log.