Skip to content

Keep compile-time hashtables in a nested map - #1367

Merged
Frotty merged 2 commits into
masterfrom
split/compiletime-hashtable
Oct 6, 2026
Merged

Frotty merged 2 commits into
masterfrom
split/compiletime-hashtable

Conversation

@Frotty

@Frotty Frotty commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Split out of #1353. It is independent of incremental compilation and changes nothing in the Lua backend.

The compile-time interpreter stored every hashtable entry in one LinkedListMultimap keyed by (parent, child), so typed lookups and flushes scanned the table. It is now nested maps keyed by parent, child and value type. Replaying a compile-time hashtable into the runtime program no longer goes through the multimap, natives are looked up once instead of once per entry, and the dead multimap path and KeyPair are removed.

Fix: an integer and a real of equal value no longer replace each other. The old multimap removed the first equals() element, so SaveInteger(h,1,1,3); SaveReal(h,1,1,3.0); SaveReal(h,1,1,5.0) lost the integer (test fails on master).

Performance: neutral for ordinary compile-time use, faster for flush-heavy use. Measured as whole compile-time test programs on this machine (noisy, three runs each, ms):

Workload master this branch
30000 parents x 1 child saved, no flush 24626 / 14726 / 15813 17775 / 14004 / 14213
10 parents x 3000 children saved 18691 / 16671 / 14553 17923 / 22178 / 15681
300 rounds of 100 fresh saves + FlushParentHashtable 793 / 302 / 342 848 / 355 / 336
8000 parents x 4 children saved, then FlushChildHashtable on half 17170 / 11917 / 12139 16382 / 9967 / 8857

The first three are within noise of each other: their time is spent in the interpreter and in replaying the saves, not in the table. Only the last, flushing children out of a large table, shows a gain (about 25-30%), because FlushChildHashtable is O(1) now instead of a scan of the whole table.

Cost: each (parent, child) slot holds a small map, so a table uses more memory per entry (roughly 150 to 380 B instead of 150 to 170 B). A micro-benchmark that creates many fresh parents and flushes them with FlushParentHashtable was about 1.5x slower in the data structure alone; it did not show up in the whole-program run above.

Tests: CompiletimeHashtableTests covers a slot with several value types, removing one child, removing only the string, the int/real case, flush child/parent, and a Lua run.

Frotty added 2 commits October 6, 2026 10:02
The interpreter stored every hashtable entry in one LinkedListMultimap keyed by
(parent, child), so flushing a parent key scanned the whole table. Use nested maps
keyed by parent, child and value type, replay them without the multimap, and look
the natives up once.
New tests cover a slot holding several value types, removing one child, removing
only the string, and an integer and a real of equal value sharing a slot (the old
multimap removed the integer when the real was removed or replaced).
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 6, 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-06T09:38:14.862340Z 12b6a99 PR opened
ℹ️ 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 added a commit to Code-Fixxers/WurstScript that referenced this pull request Oct 6, 2026
Drop changes that are split out or independent of the chunk cache and validation
cache: the hashtable rewrite and compile-time runner changes (wurstscript#1367), the
ABI-gated model invalidation (wurstscript#1368), the EliminateGenerics rewrite, parallel/fused
lowering passes, the reachable-only LocalPlayerContextAnalyzer, the w3i cache, the
closure-name suffix and timing/micro-optimisation churn. Keeps what -incremental
needs: chunk cache, PackageAbi, validation cache, modular Lua translation, the
CLI/LSP incremental pipeline and their tests.
@Frotty
Frotty merged commit 808f690 into master Oct 6, 2026
3 checks passed
@Frotty
Frotty deleted the split/compiletime-hashtable branch November 25, 2026 08:54
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