-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Hot patching systems with subsecond #19309
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
base: main
Are you sure you want to change the base?
Conversation
It looks like your PR has been selected for a highlight in the next release blog post, but you didn't provide a release note. Please review the instructions for writing release notes, then expand or revise the content in the release notes directory to showcase your changes. |
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.
Consider adding the documentation on how to setup your system (i.e. download CLI, change linker, etc.) from https://github.com/TheBevyFlock/bevy_simple_subsecond_system :)
Co-authored-by: Jan Hohenheim <jan@hohenheim.ch>
Just tried this on Linux with 2 of my existing projects. All I had to do was enable the feature and run with |
Little update: https://github.com/TheBevyFlock/bevy_simple_subsecond_system now supports changing the signatures of systems at runtime. Would be nice if this PR did so too, but I'm also fine with leaving that for a follow-up :) |
The future is now |
Co-authored-by: JMS55 <47158642+JMS55@users.noreply.github.com>
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.
A couple notes more than anything else. Really awesome to see this working, this will be a massive selling point of 0.17
@@ -140,6 +140,11 @@ where | |||
}) | |||
} | |||
|
|||
#[inline] | |||
fn refresh_hotpatch(&mut self) { | |||
// TODO: support exclusive systems |
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 there a particular blocker that made exclusive systems harder to implement?
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.
no, mostly I wanted to make sure we wanted to go in this direction before doing more work.
it should also be a todo that can be picked up by anyone among the many other things that can be continued if we get this first step in
/// Refresh the inner pointer based on the latest hot patch jump table | ||
fn refresh_hotpatch(&mut 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.
/// Refresh the inner pointer based on the latest hot patch jump table | |
fn refresh_hotpatch(&mut self); | |
/// Refresh the inner pointer based on the latest hot patch jump table | |
#[cfg(feature = "hotpatching")] | |
fn refresh_hotpatch(&mut self) {} |
If we provide a default implementation (no-op), we can safely feature-gate this method while keeping features purely additive. I think this is desirable, as the inner implementation for a user's refresh_hotpatch
might only make sense when the feature is enabled, potentially forcing them to add their own gate within the body of the function.
Alternatively, could this function be modified to be more general? E.g., refresh
?
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.
I didn't want to cfg-gate all the functions in all the implementation of that trait, but it makes sense...
Before trying to find a more general version, let's wait for systems as entities
// SAFETY: | ||
// - this is not safe | ||
// - no way | ||
// - nu uh | ||
// - not even marked as unsafe, that's how unsafe this is | ||
// - enjoy | ||
#[cfg(feature = "hotpatching")] | ||
let out = subsecond::HotFn::current(<F as SystemParamFunction<Marker>>::run) | ||
.try_call_with_ptr(self.current_ptr, (&mut self.func, input, params)) | ||
.expect("Error calling hotpatched system. Run a full rebuild"); |
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.
Perfection. Should probably try to improve this before it's merged tho.
// Connects to the dioxus CLI that will handle rebuilds | ||
// On a successful rebuild the CLI sends a `HotReload` message with the new jump table | ||
// When receiving that message, update the table and send a `HotPatched` message through the channel | ||
connect(move |msg| { |
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.
subsecond
seems to provide hot-reload handler, could it be used here?
use dioxus_devtools::{connect_subsecond, subsecond::register_handler};
...
connect_subsecond();
register_handler(Arc::new(move || {
sender.send(HotPatched).unwrap();
}));
Co-authored-by: Jan Hohenheim <jan@hohenheim.ch>
Update again: I added an opt-in to rerun hot-patched systems to the prototype. This makes it way nicer to edit UIs live, as it means we can just rerun regular |
Objective
Solution
Testing