Skip to content

Draft: Use native Lua ArrayList buffers with explicit lifetime reuse - #1545

Draft
Frotty wants to merge 3 commits into
masterfrom
codex/lua-native-collection-proposal
Draft

Frotty wants to merge 3 commits into
masterfrom
codex/lua-native-collection-proposal

Conversation

@Frotty

@Frotty Frotty commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Design hold (2026-10-22): The author does not accept the current fixed-size array[1] used as growable Lua storage and the target-specific storage plumbing as the release design. Keep this implementation as an experiment; it is not ready to merge. A replacement should define one reusable typed growable-buffer contract with explicit lifetime/capacity semantics, backend-specific storage beneath it, and no ArrayList-specific intrinsic. Generic compiler correctness/optimizer fixes should be assessed independently. Current benchmarks do not establish actual-game suitability.

ArrayList currently carries Jass arena allocation, offsets, growth copies, and free-section bookkeeping into Lua. This change uses native per-list Lua buffers while preserving the integer object identity and explicit Wurst lifetime model. Jass keeps its arena storage.

The stdlib implementation is in wurstscript/WurstStdlib2#517; this PR pins that commit and supplies the compiler support:

  • Reuse array-field buffers when object IDs are recycled, clear stale entries, and restore the correct typed default metatable, including across generic specializations. One allocator temporary is shared across fields.
  • Remove backend-constant branches before inline cost analysis so the Lua path loses Jass bookkeeping. Resolve isLua on both targets so optimized Jass drops unused native storage.
  • Preserve typed class nulls through tuple defaults instead of introducing integer zero on Lua.
  • Add regression coverage for lifetime semantics, recycled IDs/defaults, compile-time serialization, deterministic output, generated shape, and both backends.

Validation on Windows:

  • 802 focused compiler tests passed across LuaArrayListTests, LuaBackendAuditTests, OptimizerTests, DeterministicChecks, LuaTranslationTests, NewFeatureTests, ArrayTests, and CompiletimeTests.
  • 755 stdlib tests and typecheck passed; three generated-code benchmark fixture tests passed.
  • git diff --check passed. Local compiler checks skipped ErrorProne; CI remains authoritative for that check. Other hosts remain unverified.

The checked-in benchmark compiles the actual old and new ArrayList sources with the same compiler and runs their emitted Lua. Its 140 stock Lua 5.3 samples show growth/refill gains; scan and tiny-list lifetime timings are inconclusive on this noisy host. With GC stopped, maximum native heap growth after warm-up was 1.230 KiB, including 524,288 short list lifetimes, below the runner's 8 KiB gate. This is retained heap growth, not an exact allocation count or peak memory measurement.

Buffers remain strongly retained at their high-water usage and references are cleared explicitly; the implementation does not depend on garbage collection to reclaim each list lifetime. Table overhead and retained capacity still need profiling in Warcraft III. See docs/LUA_COLLECTION_STORAGE.md and the checked-in CSV for reproduction and limits.

Draft pending actual-game profiling and fresh review. No claim of a whole-map speedup.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-22T20:17:13.029515Z c82a838 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9b0491dfc4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Frotty Frotty changed the title Propose Lua-native collection storage with representation controls Use native Lua ArrayList buffers with explicit lifetime reuse Oct 22, 2026
@Frotty
Frotty marked this pull request as ready for review October 22, 2026 20:14
@Frotty Frotty changed the title Use native Lua ArrayList buffers with explicit lifetime reuse Draft: Use native Lua ArrayList buffers with explicit lifetime reuse Oct 22, 2026
@Frotty
Frotty marked this pull request as draft October 22, 2026 20:26

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant