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
Open
JavaScript: account for the fact that our JavaScript bindings use a 32-bit address space#1367agarny wants to merge 4 commits intocellml:mainfrom
agarny wants to merge 4 commits intocellml:mainfrom
Conversation
There was a problem hiding this comment.
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 anunordered_mapforAnalyserModel::areEquivalentVariables(). - Switches generator initialisation logic to use the
AnalyserModelcachedareEquivalentVariables()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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1366.