Skip to content

Lower Lua class instances to recycled integer IDs - #1264

Merged
Frotty merged 6 commits into
masterfrom
codex/lua-integer-id-objects
Aug 29, 2026
Merged

Lower Lua class instances to recycled integer IDs#1264
Frotty merged 6 commits into
masterfrom
codex/lua-integer-id-objects

Conversation

@Frotty

@Frotty Frotty commented Aug 29, 2026

Copy link
Copy Markdown
Member

Summary

  • represent every regular Lua class instance as a positive integer ID
  • store instance fields in canonical per-field Lua tables indexed by object ID
  • recycle IDs on destroy and clear inherited, reference, and array field slots before reuse
  • dispatch virtual calls through the live class descriptor while keeping direct calls direct
  • preserve class-to-index, index-to-class, instanceof, typeId, ondestroy, generics, and field-iteration behavior

This is the independent follow-up to #1261 and closes #1262.

Semantics

Wurst already has explicit destroy and ondestroy lifetime semantics. The new representation follows the Jass object model:

  • allocation reuses a free ID or increments the maximum ID
  • destroy runs existing ondestroy lowering, clears all instance storage, removes the live descriptor, then recycles the ID
  • instanceof is false for destroyed IDs
  • virtual dispatch and typeId reject dead IDs through the absent descriptor
  • after ID reuse, stale references alias the new object, matching Jass
  • closures capture the same integer ID and retain it until their explicit lifetime ends
  • array-valued fields still own Lua array tables because those values are mutable reference-like storage

Static class descriptors remain Lua tables. This removes per-instance tables and metatables only.

Directional Lua 5.3 microbenchmarks

One million allocate/write/destroy iterations:

Representation Time
instance tables 0.156 s
integer IDs plus explicit cleanup 0.078 s

Two hundred thousand retained objects, twenty field-access rounds:

Representation Time
instance tables 0.278 s
integer IDs plus static fields 0.068 s

Peak memory for two hundred thousand retained objects with two fields:

Representation Peak
instance tables 40,034 KiB
IDs, class map, and static fields 16,384 KiB

These are directional bundled-Lua 5.3 microbenchmarks, not Warcraft III frame benchmarks.

Verification

Focused tests passed:

  • LuaBackendAuditTests
  • LuaTranslationTests
  • FieldIterationTests
  • ClosureTests
  • LuaTypecastingTests
  • GenericsTests
  • GenericsWithTypeclassesTests
  • targeted lifecycle, generic-field, and field-iteration reruns after canonical-field deduplication

Coverage includes inheritance, polymorphic dispatch, instanceof, typeId, ondestroy, reference cleanup, fixed arrays, ID reuse, dead/stale references, class-index casts, generic canonical fields, and generated-output shape.

The full suite was intentionally not rerun locally; CI is authoritative.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 29, 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-08-29T09:01:46.165778Z 71a934d Manual request
ℹ️ 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.

@Frotty

Frotty commented Aug 29, 2026

Copy link
Copy Markdown
Member Author

@codex review

@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: 7bc22c8f78

ℹ️ 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".

Comment thread de.peeeq.wurstscript/src/test/java/tests/wurstscript/tests/FastHashMapTests.java Outdated
@Frotty

Frotty commented Aug 29, 2026

Copy link
Copy Markdown
Member Author

@codex review

@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: 1d25d92e4c

ℹ️ 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 commented Aug 29, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 71a934d2f4

ℹ️ 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 merged commit ab2fda6 into master Aug 29, 2026
6 checks passed
@Frotty
Frotty deleted the codex/lua-integer-id-objects branch August 29, 2026 09:19
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.

Evaluate integer-ID class lowering for the Lua backend

1 participant