-
Notifications
You must be signed in to change notification settings - Fork 192
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
Replace builders with lifetimes/setters directly on Vulkan structs #602
Conversation
a9969c9
to
90b4cd0
Compare
This may have been the $ hyperfine -p 'cargo clean -p ash' 'cargo b -p ash'
Benchmark 1: cargo b -p ash
Time (mean ± σ): 7.113 s ± 0.062 s [User: 7.927 s, System: 0.405 s]
Range (min … max): 7.053 s … 7.244 s 10 runs $ hyperfine -p 'cargo clean -p ash' 'cargo b -p ash'
Benchmark 1: cargo b -p ash
Time (mean ± σ): 5.812 s ± 0.036 s [User: 6.644 s, System: 0.356 s]
Range (min … max): 5.725 s … 5.862 s 10 runs I recall discussing earlier that the builder structs themselves likely weren't the problem, but it was down to lifetime propagation on the setter methods. Can't find that discussion anymore, but I'd love to get this in and replace trivial setters with just member updates or struct initialization, as previously discussed and proposed in #441. EDIT: Keeping in mind the twitter link at #441 (comment), would be nice to also drop setters for pointers (Rust borrows with a proper lifetime now) and "trivial slices" with a length (unique!) + pointer pair. |
let lifetime = has_lifetimes | ||
.contains(&name_to_tokens(&field.basetype)) | ||
.then(|| quote!(<'a>)); | ||
|
||
Some(quote!{ | ||
pub fn #param_ident_short(mut self, #param_ident_short: #param_ty_tokens) -> Self { | ||
self.inner.#param_ident = #param_ident_short; | ||
#[inline] | ||
pub fn #param_ident_short(mut self, #param_ident_short: #param_ty_tokens #lifetime) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this something we can do inside construction above:
let param_ty_tokens = field.safe_type_tokens(quote!('a));
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not trivially, I don't think, since it needs the has_lifetimes
state.
Nice! Can you verify whether it was the inlining or not? If so, we definitely can/should pursue it further. I don't expect that to have mattered, since I believe codegen still occurs for inline stuff (so it can only add work), but there's some conjecture there.
Per previous discussion I don't believe it's possible to avoid setters for any slice case due to ABI concerns. I'm also a bit leery of requiring a mixture of different approaches to initialize a struct; let's leave that for future work. |
$ hyperfine -p 'cargo clean -p ash' 'cargo b -p ash'
Benchmark 1: cargo b -p ash
Time (mean ± σ): 6.251 s ± 0.032 s [User: 7.082 s, System: 0.387 s]
Range (min … max): 6.176 s … 6.295 s 10 runs Seems to be both, with your initial approach netting about
Whoops, I meant to write the |
Interesting! Most ash functions should objectively be inlined, so this would be good to explore further. |
#602 introduced builder functions directly on the raw Vulkan struct types by using lifetime borrows which are FFI compatible (ABI is identical) wuth raw pointers, simplifying the whole system and protecting the user against losing lifetimes upon calling `.build()`. However, this change wasn't propagated through to the `README` so the code snippets were still showcasing removed `::builder()` and `.build()` functions and documenting "the `.build()` footgun" which doesn't even exist anymore 🎉
#602 introduced builder functions directly on the raw Vulkan struct types by using lifetime borrows which are FFI compatible (ABI is identical) wuth raw pointers, simplifying the whole system and protecting the user against losing lifetimes upon calling `.build()`. However, this change wasn't propagated through to the `README` so the code snippets were still showcasing removed `::builder()` and `.build()` functions and documenting "the `.build()` footgun" which doesn't even exist anymore 🎉
#602 introduced builder functions directly on the raw Vulkan struct types by using lifetime borrows which are FFI compatible (ABI is identical) wuth raw pointers, simplifying the whole system and protecting the user against losing lifetimes upon calling `.build()`. However, this change wasn't propagated through to the `README` so the code snippets were still showcasing removed `::builder()` and `.build()` functions and documenting "the `.build()` footgun" which doesn't even exist anymore 🎉
#602 introduced builder functions directly on the raw Vulkan struct types by using lifetime borrows which are FFI compatible (ABI is identical) wuth raw pointers, simplifying the whole system and protecting the user against losing lifetimes upon calling `.build()`. However, this change wasn't propagated through to the `README` so the code snippets were still showcasing removed `::builder()` and `.build()` functions and documenting "the `.build()` footgun" which doesn't even exist anymore 🎉
* README: Autoformat * README: Remove deprecated `builder()` snippets and guidelines #602 introduced builder functions directly on the raw Vulkan struct types by using lifetime borrows which are FFI compatible (ABI is identical) wuth raw pointers, simplifying the whole system and protecting the user against losing lifetimes upon calling `.build()`. However, this change wasn't propagated through to the `README` so the code snippets were still showcasing removed `::builder()` and `.build()` functions and documenting "the `.build()` footgun" which doesn't even exist anymore 🎉
Based on prior discussion in #441 and #483.
Remarkably, this doesn't seem to significantly impact build times despite deleting on the order of 20k(!) lines of code. Arguably still an improvement for the sake of simplicity and safety, though. Could use confirmation on the build impact by someone with a better test environment.
TODO: Try making all the setters by
&mut
rather than by value, per discussion in #483.