←back to thread

146 points returningfory2 | 2 comments | | HN request time: 0.884s | source
Show context
pitaj ◴[] No.43645579[source]
This actually is niche optimization. The outer enum is using the niches available in the tag of the inner enum for its own discriminant.

The author seems to have a limited understanding of niche optimization.

replies(1): >>43646157 #
1. returningfory2 ◴[] No.43646157[source]
In the strictly technical sense I agree, however in the Rust community when people say "the niche optimization" they usually are referring only to the simplest case. For example in the book Rust For Rustaceans (written by a pretty serious Rust expert and aimed at intermediate-level Rust programmers) the nice optimization is described as "the Rust compiler using invalid bit patterns to represent enum variants that hold no data". Note the "hold no data" part - it doesn't incorporate the case in the blog.

In any case, the definition of what is exactly niche optimization is besides the point. The point of the post is: the literature gives you the impression that there's one limited form of enum size optimization in the Rust compiler, but in fact there are other optimizations too. And knowing this is useful!

replies(1): >>43662021 #
2. Dylan16807 ◴[] No.43662021[source]
> In any case, the definition of what is exactly niche optimization is besides the point. The point of the post is: the literature gives you the impression that there's one limited form of enum size optimization in the Rust compiler, but in fact there are other optimizations too. And knowing this is useful!

It's useful if you got that specific impression.

But I didn't. So I was disappointed and unenlightened because I was promised a non-niche optimization and I didn't get one.