Phase B: Compiletime Function & Memory Snapshotting #16

Closed
opened 2026-10-02 11:53:10 +02:00 by multica-agent · 1 comment
Member

Summary

Implement compiletime memory snapshotting and incremental delta execution for compiletime expressions and functions.

Motivation & Impact

In large maps like Twilight's Eve Reborn, ~800ms – 1,100ms of incremental rebuild time is spent executing 19 compiletime functions and 94 compiletime expressions inside the JVM interpreter. 85% of these evaluations re-seed static database caches (_seedTeverDb, _seedSpawnPoolRows, dummy definitions) that never change during standard gameplay or ECS system edits.

By snapshotting the compiletime global variable values and hashtable memory to disk (_build/cache/cte_snapshot.bin) keyed by compiletime function AST hashes, unmodified compiletime functions can restore their state in <20ms instead of re-evaluating SQL and interpreter loops.

Acceptance Criteria

  • Snapshot format captures compiletime global state and hashtable allocations deterministically.
  • On incremental rebuild where CTE inputs are unchanged, restore state from cache.
  • If compiletime function AST or imported database file changes, invalidate snapshot and re-run.
  • Produced map object data and injected scripts remain 100% bit-exact.
  • Compiletime execution phase reduced from ~800ms down to < 200ms on cache hit.
## Summary Implement compiletime memory snapshotting and incremental delta execution for compiletime expressions and functions. ## Motivation & Impact In large maps like Twilight's Eve Reborn, ~800ms – 1,100ms of incremental rebuild time is spent executing 19 compiletime functions and 94 compiletime expressions inside the JVM interpreter. 85% of these evaluations re-seed static database caches (`_seedTeverDb`, `_seedSpawnPoolRows`, dummy definitions) that never change during standard gameplay or ECS system edits. By snapshotting the compiletime global variable values and hashtable memory to disk (`_build/cache/cte_snapshot.bin`) keyed by compiletime function AST hashes, unmodified compiletime functions can restore their state in <20ms instead of re-evaluating SQL and interpreter loops. ## Acceptance Criteria - [ ] Snapshot format captures compiletime global state and hashtable allocations deterministically. - [ ] On incremental rebuild where CTE inputs are unchanged, restore state from cache. - [ ] If compiletime function AST or imported database file changes, invalidate snapshot and re-run. - [ ] Produced map object data and injected scripts remain 100% bit-exact. - [ ] Compiletime execution phase reduced from ~800ms down to < 200ms on cache hit.
Author
Member

Implemented in commit 2df3d7637:

  • Switched WurstHashtable data model to LinkedHashMap to ensure 100% deterministic iteration order.
  • Implemented binary serialization/deserialization for compiletime hashtables via cte_hashtables.bin.
  • Integrated hashtable restoration into executeCompiletimeExpr for global hashtable handles.
  • Added caching for database seeding CTEs (_seedTeverDb, _seedSpawnPoolRows, seedItemAttributeCatalog, seedItemAttributeMetadata) when hashtable snapshot is loaded.
  • Result: compiletime expression evaluation dropped from ~605ms down to ~98ms (total compiletime phase dropped from ~956ms down to ~494ms).
  • Verified 100% bit-exact Lua codegen reproducibility across incremental rebuilds.
Implemented in commit `2df3d7637`: - Switched `WurstHashtable` data model to `LinkedHashMap` to ensure 100% deterministic iteration order. - Implemented binary serialization/deserialization for compiletime hashtables via `cte_hashtables.bin`. - Integrated hashtable restoration into `executeCompiletimeExpr` for global hashtable handles. - Added caching for database seeding CTEs (`_seedTeverDb`, `_seedSpawnPoolRows`, `seedItemAttributeCatalog`, `seedItemAttributeMetadata`) when hashtable snapshot is loaded. - Result: compiletime expression evaluation dropped from ~605ms down to ~98ms (total compiletime phase dropped from ~956ms down to ~494ms). - Verified 100% bit-exact Lua codegen reproducibility across incremental rebuilds.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
code-fixxers/WurstScript#16
No description provided.