Scratch param#24140
Conversation
|
There was a suggestion on the original issue to make |
052f442 to
b8ee91e
Compare
Is it possible to overcome this? Also |
I don't think so. Not at least while maintaining panic safety. The way it would work is we would add a new method to // ...
let params = unsafe {
F::Param::get_param(&mut state.param, &self.system_meta, world, change_tick)
}?;
/// <ignore hotpatching impl>
let out = self.func.run(input, params);
/// We would add a `post_system_run` call here
self.system_meta.last_run = change_tick;If |
|
I'm pulling this out of draft since this version is mostly done. I'll hold off on writing the showcase until I get at least one review. Hopefully, the safety issue can be hashed out and we get to push the best versions of this across the finish line. |
| } | ||
|
|
||
| /// SAFETY: We only access world change ticks immutably. We can't conflict with anything. | ||
| unsafe impl<'a, T: ClearableCollection + FromWorld + Send + Sync + 'static> SystemParam |
There was a problem hiding this comment.
Local does not require Sync, why Scratch require it?
This was the whole motivation for this code.

Objective
Introduce a system param for collections holding scratch data.
Closes #23775
Solution
Implement two new items to
bevy_ecs:ScratchandClearableCollection.Scratchis the new system param for hodling scratch data. It holds aClearableCollectionwhich it clears on every system run.I went with a trait based solution instead of
ScratchVec<T>to prevent duplication of the capacity management code. That said I tried to not over-complicate the capacity management code itself. It currently just runs a 10 000 tick timer that resets every time the allocation capacity grows. If it runs down we try to halve the allocation size.Testing
The PR comes with 2 new tests, but I still want to benchmark how using this affects render asset extraction (which is why this pr is a draft for now).
Showcase
TODO