Skip to content

JavaScript: account for the fact that our JavaScript bindings use a 32-bit address space#1367

Open
agarny wants to merge 4 commits intocellml:mainfrom
agarny:fixes
Open

JavaScript: account for the fact that our JavaScript bindings use a 32-bit address space#1367
agarny wants to merge 4 commits intocellml:mainfrom
agarny:fixes

Conversation

@agarny
Copy link
Copy Markdown
Contributor

@agarny agarny commented Apr 9, 2026

Fixes #1366.

Copilot AI review requested due to automatic review settings April 9, 2026 00:54
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates libCellML’s cached variable-equivalence logic to avoid cache-key collisions in 32-bit address spaces (notably the JavaScript/WASM bindings), addressing incorrect cache hits on very large models (Fixes #1366).

Changes:

  • Replaces the Cantor-pairing-based cache key with a (uintptr_t, uintptr_t) key in an unordered_map for AnalyserModel::areEquivalentVariables().
  • Switches generator initialisation logic to use the AnalyserModel cached areEquivalentVariables() API.
  • Adds (currently disabled/commented-out) large-model regression tests across C++, Python, and JavaScript bindings.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/analysermodel.cpp Uses a pointer-pair key for cached equivalence results to avoid 32-bit overflow collisions.
src/analysermodel_p.h Introduces VariableKeyPair + custom hash and moves cache storage to unordered_map.
src/generator.cpp Routes equivalence checks through mAnalyserModel->areEquivalentVariables() (cached).
tests/generator/generator.cpp Adds a large-model regression test, but it is commented out.
tests/bindings/python/test_generator.py Adds a large-model regression test, but it is disabled via a triple-quoted block.
tests/bindings/javascript/generator.test.js Adds a large-model regression test, but it is commented out; also introduces unused imports.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

agarny added 3 commits April 9, 2026 13:54
Note that the test is disabled since it performs repeated parse/analyse/generate loops, which take several minutes to complete. So, it should be enabled only when needed, and not as part of our regular test suite.
... rather than the generic areEquivalentVariables() method which doesn't include caching.
Indeed, in our WebAssembly module, the key was 32-bit (while 64-bit in C++/Python) which caused collisions and incorrect cache hits.

So, we replaced the Cantor-pairing key and std::map-based cache with a typed VariableKeyPair and std::unordered_map. This makes the cached-equivalence lookup more explicit, portable, and efficient.
This enforces an ordered, deterministic container for identifier lists and consolidates the type via the IdList typedef.
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.

JavaScript: account for the fact that our JavaScript bindings use a 32-bit address space

2 participants