This document outlines the major architectural optimizations implemented to accelerate the ProXPL Virtual Machine. These changes represent a transition from a baseline interpreter to a high-performance threaded runtime.
Fixed a critical architectural bug in the experimental threaded dispatchers where the jump table was being rebuilt every iteration.
- Files:
src/vm/vm_dispatch.c,src/vm/vm_core_opt.c - Improvement: Jump table is now initialized once before the hot loop.
- Impact: Enables true computed-goto performance (~1.5x-2x speedup on GCC/Clang).
- Safety: Added
do_INVALIDtrap handlers to all 256 opcode slots to prevent undefined behavior on unrecognized bytes.
The primary execution loop now caches the most volatile pointers in local CPU registers.
- File:
src/runtime/vm.c - Details:
ip(Instruction Pointer) andstackTopare now localregistervariables.- Reduced memory traffic by avoiding constant structure dereferencing.
- Implemented
STORE_FRAME()andLOAD_FRAME()synchronization primitives for C-call safety.
Implemented a single-level inline cache for global variable lookups to bypass hash table overhead.
-
Infrastructure: Added
cachefield toObjFunctionandGICEntrystructure invm.h. -
Logic:
- On first access, the variable's entry address and table pointer are cached.
- Subsequent accesses verify the table pointer (to handle rehashes) and perform a direct memory read.
-
Impact: Turns
$O(n)$ hash probes into$O(1)$ direct access.
Optimized the core mapping logic in the Table implementation.
- File:
src/runtime/table.c - Optimization: Replaced expensive modulo (
%) with bitwise AND (&) for indexing. - Prerequisite: Ensured all table capacities are powers of two (already guaranteed by growth logic).
| Optimization | Target Metric | Expected Gain |
|---|---|---|
| Threaded Dispatch | Instruction Overhead | 30% - 50% |
| Register Caching | Memory Traffic | 15% - 20% |
| Inline Caching | Global Variable Speed | 200% - 400% |
| Bitwise Indexing | Table Lookup Latency | 5% - 10% |
ObjFunction: Now includes avoid* cachewhich is GC-managed (freed ingc.c).Table: NewtableGetEntry()function provides directEntry*access for caching systems.VMLoop: All opcode handlers inrun()must now use localipandstackTopand callSTORE_FRAME()before any operation that might trigger a GC or use the VM's global state.
Status: Milestone 1 Complete