JavaScript: account for the fact that our JavaScript bindings use a 32-bit address space#1384
Open
agarny wants to merge 2 commits intocellml:mainfrom
Open
JavaScript: account for the fact that our JavaScript bindings use a 32-bit address space#1384agarny wants to merge 2 commits intocellml:mainfrom
agarny wants to merge 2 commits intocellml:mainfrom
Conversation
... 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.
There was a problem hiding this comment.
Pull request overview
This PR fixes cache collisions in AnalyserModel::areEquivalentVariables() when used from the JavaScript (32-bit address space) bindings by changing the cache key strategy to avoid overflow-prone pairing.
Changes:
- Replaced Cantor-pairing-based cache key with a
(v1, v2)pair key in anunordered_map. - Canonicalized variable address ordering via
std::swapbefore caching/lookup. - Updated generator code to use the cached
AnalyserModel::areEquivalentVariables()method.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/generator.cpp |
Switches variable equivalence checks to use AnalyserModel’s cached method. |
src/analysermodel_p.h |
Replaces the cache storage with an unordered_map keyed by a pointer-pair struct and custom hash. |
src/analysermodel.cpp |
Updates areEquivalentVariables() to use the new key type and cache lookup/insert logic. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
hsorby
approved these changes
Apr 24, 2026
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.