-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
CtxRef::clone is a footgun #1005
Comments
You are right in pointing this out - I thought I had documented it, but looking at it now it seems I have forgotten it. The reason for it is performance and ergonomics. Everything in There is perhaps some other design that can get the best of two worlds. |
I was actually thinking about the use of mutexes as well. Specifically, without multi_threaded set, the library is thread-safe in that it doesn't have UB if the |
I tried it out and came up with this, which makes |
Nice! How does |
I added another commit that properly integrates it with the thread safety feature flags. The cargo bench result is:
|
Are the benchmarks |
I created a draft PR for easier reviewing of your progress! |
I've run the benchmark a few times, and the numbers look good. I like this approach! I think I gave up on it because I didn't manage to find When I tested I found two issues:
I also think the Do you have more time to work on this? |
Switching from That change is also not an ergonomic feature, but an optimization, so should be a separate PR/issue. |
I'm continuing this work in #1050 and will try to get it mergable asap! |
The docs for
CtxRef
prominently mention that it's anArc
and that it's cloneable. But starting a new frame mutates, not the context, but theCtxRef
, invalidating prior clones. I'm sure there's a good reason for this, but in most libraries that give cloneable "handle" types (eg winit, wgpu, etc), mutating methods only affect the thing the handle points to, not the handle itself. I think the API and docs shouldn't suggest thatCtxRef
andContext
are handles, or at least mention that they're handles only for the duration of one frame.The text was updated successfully, but these errors were encountered: