Back to News
Advertisement
Advertisement

⚡ Community Insights

Discussion Sentiment

100% Positive

Analyzed from 200 words in the discussion.

Trending Topics

#clippy#rust#run#box#things#linter#different#variant#doesn#actually

Discussion (6 Comments)Read Original on HackerNews

mstange•about 1 hour ago
Are 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"
gizmo686•about 1 hour ago
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 also doesn't address the situation in the article at all.

dwattttt•about 1 hour ago
squirrellous•8 minutes ago
I wonder from time to time whether you can decide the best “schema shape” beforehand, ie before you can run real workloads that stress the memory implications of such things. This can be very useful if you are trying to decide the boundary of some public facing API, but for whatever reason can’t run benchmarks (lack of impl, data, time, etc).

Without that, if you try to suggest a transformation like this when the schema is first conceived, it will likely be considered premature optimization.

krautsauer•about 2 hours ago
[Edit:deleted]
stebalien•about 2 hours ago
Box<str> is still two words (length and pointer). That's better than the 3 words (length, pointer, capacity) for strings, but Box<String> is one word (not including the heap allocation).