Repository navigation
Description
Motivation
The Lua backend currently represents every Wurst class instance as a Lua table with a shared per-class metatable. destroy runs the lowered ondestroy path but ImDealloc itself is deliberately a no-op, leaving reclamation to Lua GC.
Wurst/Jass instead uses integer object IDs plus static per-field arrays and explicit reuse. Since Wurst already exposes destroy/ondestroy, the Jass representation may be a better performance fit for allocation-heavy Lua maps too.
Initial benchmark
Synthetic benchmark on the compiler's bundled Lua 5.3 runtime, using a three-field object (x, y, ref), a shared metatable for table instances, and a free-list allocator with parallel field arrays for integer IDs:
| workload | instance tables | integer IDs + field arrays |
|---|---|---|
| 1,000,000 allocate/use/free cycles | 0.173 s, ~13 KiB residual | 0.099 s, ~0 KiB residual |
| retain 200,000 instances | ~40 MiB | ~12 MiB |
| 20 rounds reading two fields on 200,000 instances | 0.216 s | 0.063 s |
These are directional microbenchmarks, not yet a decision. The follow-up should benchmark generated Wurst code and realistic WC3 workloads before changing emission.
Semantic compatibility questions
destroytoday leaves Lua table aliases fully usable. Integer-ID reuse would instead match Jass more closely: checked builds should reject use-after-destroy, while unchecked stale aliases may observe a recycled object.- Deallocation must clear every reference-bearing field (including inherited fields, module fields, generic specializations, tuple-split fields, and closure captures) before returning an ID to a free list, or Lua GC retention worsens.
- Lua currently reclaims objects and closure objects whose source code omitted
destroy; an explicit allocator would leak those IDs. Decide whether all such lifetimes are statically enforced, automatically released, or intentionally remain GC-backed. - Preserve
ondestroyordering, dynamic dispatch, equality/null behavior,instanceof, type IDs, casts/index conversions, constructor failure behavior, and class/interface dispatch slots. - Decide whether allocation pools are global or per concrete class, and how runtime type checks prevent cross-class stale references.
Proposed gates for a follow-up PR
- behavioral parity tests for construction, inheritance, interfaces,
ondestroy, double destroy, stale aliases, null, casts, and checked/unchecked dispatch - reference-cleanup tests using collectable sentinel tables/weak references in the Lua harness
- closure lifetime tests, especially captured class references and callbacks stored by events
- generated-output assertions proving instance allocation creates no per-instance Lua table
- generated-Wurst benchmarks for allocation churn, retained instances, field reads/writes, dispatch, destruction, and GC pauses
- full Lua/Jass regression suites before merging
Activity