Dedupe vm constants - #726
Conversation
(except when defining derived unit constants, as initially identical but temporary values) Don't see any real performance changes from this (if anything it's probably a minor slowdown due to the added dupe check in `add_constant`). However, it does reduce the number of constants generated from the prelude from ~730 to ~320, a reduction of 56%. This in theory allows for larger Numbat programs as it's now harder to hit the ~65k constants ceiling. Worth it? I don't know :)
…truction, instead *requiring* `new_dummy` to construct a Dummy
…it can't already exist)
… constants might not be found
…be the last index
|
Thank you for working on this. Before I review this, I'd like to understand the core motivation better. Is there any upsides to this beside what's mentioned in the PR description at #712 (comment)? |
|
I believe this implementation allows for constant-time lookup of stored values, whereas the referenced implementation uses linear lookup (calls to .iter().position()) |
I'm skeptical about this part. This won't work if we want to replace our number representation, right? |
I was thinking this could be a step in that direction. Disentangling the underlying representation by making it opaque. I might be missing some consequences though. |
|
Making it opaque is certainly a good idea, but it sounded like we use the bits of the f64 for the integer? How would that work for some more complex heap-allocated precision datatype? |
The
I believe the only methods that would have to be updated are Edit: oops, this representation breaks |
|
Sorry for the late reply here. I'm still skeptical about the added complexity and potentially decreased flexibility w.r.t. the number format, especially since the benefits don't seem immediately clear (there are no benchmarks that would show better performance, for example). To be honest, I currently also don't have a lot of time to review this, so I'd like to close this for now. If you (or anyone else) thinks that this is a mistake, please feel free to comment here, and we can reconsider. |
Builds on #712 by making
Constant: Hashso that we can stick it in anIndexSet. Therefore all the deduplication logic can rest solely on the nature of anIndexSet.This required quite a few changes. Most notably,
Numberis now opaque instead of providing access to its contained f64 via.0because it no longer contains an f64, but rather a u64, which is converted to and from an f64 withf6::to_bits/f64::from_bits. But also, we have a newDummyvariant inConstantthat stores a distinct value each time it's created. (This is of course necessary for the deduplication logic to work correctly; identical dummies would occupy the same slot in the map.)