-
Notifications
You must be signed in to change notification settings - Fork 976
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
Use concrete Future
types in public API
#2970
Conversation
52f67ac
to
0da63f0
Compare
I don't think I understand this change. What problem is solved by replacing the |
Currently, one can't save the returned This is a very common pattern in Rust async code, either things are implemented with |
Okay, I see. Can you say more about winit's requirements, such that something like this isn't adequate?
|
Since rust-windowing/winit#1922, we have found out that we should not create a window until
This was perfectly adequate before, because it was outside the loop. Now that we have to do this inside the loop, we can't just block anymore. For obvious reasons, you can't just block inside the event loop, in this context this was already noticed here rust-windowing/winit#1992 (comment). There are alternative solutions, like doing the initialization in a thread, on the web you have to do it via a spawned |
In every situation where you're using
(There's actually no reason for these methods to be async on native in the first place.) |
I'm using
For native that would work, it just doesn't work for web because of the closure, that would need to be boxed, because it takes a moved context. That's why the custom |
Okay, I see now: So the purpose of this change is to avoid calling |
It's to avoid |
My judgment is that it isn't worth the complexity of this change to avoid boxing a value, usually once in the execution of the program. If another maintainer has a different opinion, feel free to re-open this. |
I have some ideas on how to make this PR better, if the problem is added complexity, I can reduce the amount of code and keep the logic local to where it was. I will update this PR so you can take a look and see if that changes your opinion. |
I would take a change to have |
I believe that's actually even worse, that would force allocation even in the case where none was needed. As far as I understand, the problem is that it just makes the code worse with no appropriate gain. So my suggestion would have been to figure out a way to not make the code worse and not introduce additional complexity, would that be acceptable? |
We're talking about two boxes, over (typically) the course of an entire execution. It's just not worth your time. |
I'm a bit confused, boxing them outright does literally nothing useful, at least nothing I can come up with. If a user needs a concrete type, they can easily just wrap it in a
Clearly it's worth the time to me, otherwise I wouldn't have made this PR. I completely agree though, that saving two allocations at this point is completely irrelevant and doesn't improve performance in any measurable way. But I think I got the message, this "improvement" isn't worth the added complexity, no matter how much I would |
I'm sorry - it's not my place to say what's worth someone's time. You're correct that I don't think this change is a net win; I'd need to see more impact. Improvements in time, memory, and ergonomics are all on the table. |
I think we agree that there are no improvements on time or memory, personally I made this change more for user-experience than anything else. Personally when I write or review code, I look out for unnecessary allocations or reference counting. Every time I see a There is also the case for increased complexity for the user by making it more difficult to name the type when they need to. This has also been discussed in the official API guidelines here: rust-lang/api-guidelines#60. I think the crux of the problem is comparing the pro vs contra here. The pro is very very small, if present at all. The contra, added code complexity, seems to be big enough for you, to overshadow the pro here. I did try to reduce the code complexity a bit, but found out that the difference was negligible. I guess rust-lang/rust#63063 would basically reduce the added code complexity to zero. I want to point out that I do appreciate the skepticism and scrutiny here. I don't want the Another idea that I just had was adding a native only extension to allow for sync alternatives to these two functions. Would that be in scope? Pros
Cons |
That's actually where I'm leaning as well - simply have The catch is that some of the other wgpu maintainers are not on board with this proposal. They want So basically:
If someone were to call this bikeshedding (an unwarranted focus on a minor issue, simply because it's something everyone can understand and feels qualified to have an opinion about), I might feel like that criticism hits its mark. In my defense, I'd say that this API is literally the first thing that anyone trying wgpu needs to call, and I suspect it leaves an impression. |
I think at least one of the methods should be supported on both. That way if you need portability you can use the async function, and if you don't you can use the blocking function, but you never need to use both. Given that the async version already works on both, I don't see why it would be an issue to keep that on both. |
I believe I'm missing a bit of context to fully understand every point you are making @jimblandy.
I'm not sure how you imagine Maybe I also completely misunderstood what this API is supposed to do.
I agree with the other
From personal experience I know that this isn't always necessary. In fact most of the programs I've written with
You should try it, with the addition of the WebGL backend it has become quiet straightforward today! I hope I didn't misunderstand anything and explained my point of view understandably! On how to move forward, I was really thinking of what @Diggsey was proposing, just adding a native only method, leaving the |
Checklist
cargo clippy
.RUSTFLAGS=--cfg=web_sys_unstable_apis cargo clippy --target wasm32-unknown-unknown
if applicable.Connections
None.
Description
I am trying to implement a render state that can be polled to finish
request_adapter
andrequest_device
instead of usingawait
. This has come up because of rust-windowing/winit#2051, now we have to callrequest_adapter
andrequest_device
inside the event loop, which isn't allowed to block.Testing
Actually quiet well tested by the existing infrastructure.