Box to save memory in Rust
dystroy.org
Box to save memory in Rust
1–10 of 59 posts
Re: Box to save memory in Rust
#2Re: Box to save memory in Rust
#3[Edit:deleted]
Re: Box to save memory in Rust
#4Re: Box to save memory in Rust
#5Are there any tools that help finding these kinds of things? Like a profiler that says "80% of the allocated bytes are objects of this type, with 95% of those having that field set to None"
Clippy is essentially a linter; and one of its checks catches cases where different enum variants have a significantly different size; with a suggestion to Box the larger variant.
Since this is just a linter, it doesn't actually have any knowledge of how frequently each variant is actually used. It also doesn't address the situation in the article at all.
Re: Box to save memory in Rust
#6Are there any tools that help finding these kinds of things? Like a profiler that says "80% of the allocated bytes are objects of this type, with 95% of those having that field set to None"
The closest I am aware of is clippy (`cargo clippy` in a standard Rust project will run it with default configurations). Clippy is essentially a linter; and one of its checks catches cases where different enum variants have a significantly different size; with a suggestion to Box the larger variant. Since this is just a linter, it doesn't actually have any knowledge of how frequently each variant is actually used. It…
Re: Box to save memory in Rust
#7Re: Box to save memory in Rust
#8Without that, if you try to suggest a transformation like this when the schema is first conceived, it will likely be considered premature optimization.
Re: Box to save memory in Rust
#9It's especially problematic because traits don't have memory behaviors like this article in most cases - by default they're unsized, because it's a description of behavior, not data, and you can't even use them as a struct field without extra work.
Like, replace "trait" in here with "box" and see how confusing it would be to be describing how you saved memory by boxing your box, because option doesn't box like many other languages do.