-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend null-pointer enum optimization to nested enums #23228
Comments
Oh dang I thought this worked today. Been listening to too many pipedreams on internals. |
@gankro well, actually, we already cover structural nesting, and the null-pointer enum optimization produces structures, so what's left is to also recurse through those - might be a bit hard to keep track of fields that are already "taken" - but everything else is there. |
Are these optimizations documented somewhere aside from the compiler internals? It seems like something that might come up fairly often though the list might get extremely long. I'm not sure. |
@mdinger The books has a paragraph on "nullable pointer optimization" in the FFI chapter. |
@killercup Okay good. |
Triage: no change. |
With rustc 1.26 @eddyb You've stated in rust-lang/rfcs#1230 (comment) that further changes have tradeoffs that require RFCs.
This should probably be closed then, right? |
CC @rust-lang/wg-codegen |
This requires more words to be initialised even in the case of None, and as far as I know that may lead to worse performance. |
I'm perfectly willing to have this closed if someone on the compiler team confirms that this specific optimization requires too many tradeoffs to be valuable. Part of my original intent in filing this issue was to spur people to consider the theoretical limits of enum optimization, which was limited in 2015 but much more capable today. |
Closing as per the rationale in my previous comment; Rust is far more capable of doing niche optimizations where it makes sense than back when this issue was originally filed in 2015, and it's unclear that this specific memory optimization is actually desirable. |
Theoretically,
Option<Option<Option<(Box<u8>, Box<u8>, Box<u8>)>>>
should be able to leverage the null-pointer optimization such that it takes up no more space than(Box<u8>, Box<u8>, Box<u8>)
. Implement this for arbitrary levels of nesting.The text was updated successfully, but these errors were encountered: