Use sparse bitsets instead of dense ones for NLL results#48245
Use sparse bitsets instead of dense ones for NLL results#48245bors merged 4 commits intorust-lang:masterfrom
Conversation
d1d264a to
de71da1
Compare
ee64b73 to
21aa4d8
Compare
|
Do we have data about how much this improves memory usage? And what its cost in execution time is, if any? |
|
@pnkfelix we should profile this 👍. I just started this as a wip thing and ended being a working solution quickly. I know the code is bad in some parts so I didn't bother until now to run benchs. I think I should do it now and then tidy up the code a bit 😃. |
There was a problem hiding this comment.
If we are going to use a type I, then I think this should be
SparseBitMatrix<R, C> where R: Idx, C: Idx {
vector: IndexVec<R, SparseBitSet<C>>
}There was a problem hiding this comment.
and this would be IndexVec::from_elem_n(SparseBitSet::new(), rows)
There was a problem hiding this comment.
and this would be row: R, column: C
There was a problem hiding this comment.
then this would be SparseBitMatrix<RegionVid, RegionElementIndex> -- and some casting below would go away
21aa4d8 to
ffc357d
Compare
|
PR is now ready, I still need to run benchs, etc. Going to do that next. |
|
Using steps to reproduce here rust-lang/rust-memory-model#26 I see the following ... As you can see we have a little gain here, unsure if it's what @nikomatsakis expected or if he expected more :/. I was algo trying to profile memory valgrind's massif, and I'm getting a segfault, unsure if you have made this run and how with rust ... |
I did not expect a big impact here on this particular test case. But I think this will be more important on larger test cases. And the fact that we saw a small improvement means we're not paying a price for the improved memory usage. |
There was a problem hiding this comment.
to avoid the clone, add a helper function like this one. Maybe we should add that somewhere else, if we don't have it already.
There was a problem hiding this comment.
I bet this method can just be removed. But if not, it could be made faster by adding a method intersection on SparseBitset. I guess it would work something like this:
let mut result = SparseBitset::new();
for (key, value) in self.map {
match other.map.get(key) {
None => { /* other has no values with these key */ }
Some(other_value) {
if value & other_value != 0 {
result.map.insert(key, value & other_value);
}
}
}
}This of course generates a new sparse-bitset.
9305336 to
edc764e
Compare
There was a problem hiding this comment.
Let's add a comment here?
Something like:
Return mutable references to two distinct elements, a and b. Panics if a == b.
Also, maybe we could call it get2_mut? (similar to get_mut?)
There was a problem hiding this comment.
At least I think we should add a _mut suffix
There was a problem hiding this comment.
Let's not call it get2 since it doesn't return an Option (as get does).
There was a problem hiding this comment.
Either:
- This should be
&mut Self::Itemand there is no need for theTparameter
Or:
- Remove the
type Item
There was a problem hiding this comment.
I have to say, pushing up the "index types" is nice.
f3af3f7 to
d5811f7
Compare
|
@bors r+ |
|
📌 Commit d5811f7 has been approved by |
|
Could this use the chunked API from #47575 (comment)? |
There was a problem hiding this comment.
this could be made faster with chunks, right? (this is going a bit at a time, right, not a word at a time?)
There was a problem hiding this comment.
(I think @spastorino and I talked about that already at some point...)
There was a problem hiding this comment.
this could probably use chunks
There was a problem hiding this comment.
we'd have to look at the callers of these add methods...
|
(from IRC) |
|
@eddyb I'm inclined to land some variant of these changes, but otherwise let you revise and merge this with your own API when that is making progress. Seem reasonable? |
d5811f7 to
6a74615
Compare
|
@bors r+ |
|
📌 Commit 6a74615 has been approved by |
|
@nikomatsakis Yeah. Context is @spastorino explicitly asked for me to leave a comment on GitHub. |
|
As an aside, @spastorino if you format your pull request description with a line that says "Resolves #48170" instead of "this is for", GitHub will automagically link the PR and issue, and resolve the issue if/when the PR merges. Just a helpful usage hint. 😄 |
…tsakis Use sparse bitsets instead of dense ones for NLL results This is for rust-lang#48170. r? @nikomatsakis
This is for #48170.
r? @nikomatsakis