Skip to content

Support hotpatching systems #19296

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

Open
janhohenheim opened this issue May 19, 2025 · 16 comments · May be fixed by #19309
Open

Support hotpatching systems #19296

janhohenheim opened this issue May 19, 2025 · 16 comments · May be fixed by #19309
Labels
A-ECS Entities, components, systems, and events C-Feature A new feature, making something new possible C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Complex Quite challenging from either a design or technical perspective. Ask for help! D-Unsafe Touches with unsafe code in some way S-Needs-Design This issue requires design work to think about how it would best be accomplished X-Blessed Has a large architectural impact or tradeoffs, but the design has been endorsed by decision makers

Comments

@janhohenheim
Copy link
Member

janhohenheim commented May 19, 2025

What problem does this solve or what need does it fill?

A common complaint from Bevy users is the relatively high iteration time. Hotpatching is a nice solution for this, as it allows code changes to affect the running binary.

What solution would you like?

While many things can be hotpatched, I think implementing it for systems is a nice start. This way, users could already start live-editing their UIs by changing a system that re-inserts a UI node hierarchy in Update, for example.

What alternative(s) have you considered?

  • Don't implement it
  • Start with hotpatching another area of Bevy
  • Leave it to third-party crates like dextrous-developer

Additional context

Recently, Dioxus has released an alpha of subsecond, which implements exactly this. One of their explicit goals is to make this technology available for other frameworks such as Bevy.
If we go this route, there is already a Bevy integration demo. Per @jkelleyrtp, this is not meant as a long-term end-user API, but to give Bevy maintainers and early adopters today an example of how to wire stuff up. We need to spend some time working on the integration between the two, in order to ensure it is safe.

@janhohenheim janhohenheim added C-Feature A new feature, making something new possible A-ECS Entities, components, systems, and events D-Complex Quite challenging from either a design or technical perspective. Ask for help! S-Needs-Design This issue requires design work to think about how it would best be accomplished D-Unsafe Touches with unsafe code in some way C-Usability A targeted quality-of-life change that makes Bevy easier to use labels May 19, 2025
@alice-i-cecile
Copy link
Member

The maintainers are keen on supporting hot reloading in Bevy itself, and at least personally, I would prefer to colalborate with the rest of the ecosystem.

Before adopting this fully, I'd like more investigation / docs into exactly how this would be used by Bevy devs, and the constraints and risks imposed. We don't have a ton of bandwidth to investigate this fully (nor do I personally have the requisite expertise on the technical / implementation side), so I would really value a cohesive design doc or other write-up.

@janhohenheim janhohenheim added the X-Blessed Has a large architectural impact or tradeoffs, but the design has been endorsed by decision makers label May 19, 2025
@janhohenheim
Copy link
Member Author

Here's a little something I threw together to use in the meantime :)
https://github.com/janhohenheim/bevy_simple_subsecond_system

@alice-i-cecile
Copy link
Member

@hecrj
Copy link

hecrj commented May 31, 2025

I am interested in integrating subsecond into iced as well.

I feel that the part of the puzzle that is missing is a standalone version of dx serve --hot-patch (i.e. a server implementing the subsecond protocol). Ideally, it'd be a cargo subcommand (e.g. cargo hot) acting as a drop-in replacement of cargo run.

This way, the whole ecosytem can benefit without specifically depending on the Dioxus build process.

I'm not sure if there are any efforts in this direction, but I will look into isolating the relevant parts of dioxus-cli soon myself.

@alice-i-cecile
Copy link
Member

I feel that the part of the puzzle that is missing is a standalone version of dx serve --hot-patch (i.e. a server implementing the subsecond protocol). Ideally, it'd be a cargo subcommand (e.g. cargo hot) acting as a drop-in replacement of cargo run.

This is something that Bevy is interested in too :)

@hecrj
Copy link

hecrj commented Jun 1, 2025

Cool!

I am working on it over here: https://github.com/hecrj/cargo-hot

I've got the Fat linking stage working. Now I'm getting to the fun part. Will keep you posted.

@jkelleyrtp
Copy link

jkelleyrtp commented Jun 1, 2025

Cool!

I am working on it over here: https://github.com/hecrj/cargo-hot

I've got the Fat linking stage working. Now I'm getting to the fun part. Will keep you posted.

I get that dioxus is open source, but we've been working on this for the better part of the last year and seeing our work immediately ripped out like this is upsetting.

The least you could do is help us spin dx out into a general tool for anyone in the ecosystem, not just clone our work wholesale and package it into another tool.

There are bugs and dragons abound and big work ahead like proper workspace support. Lots of sweat and long nights went into this, hand-rolled assembly, and head banging to figure out esoteric hacks to get it working. I would love it if the community came together to help maintain a "cargo plus plus", not just extricate our work to put their own name on it.

It's understandable if some random fly-by contributor did this, but the head of another large rust project doing it without even reaching out is disappointing.

@teohhanhui
Copy link

"cargo plus plus"

That's how you kill an ecosystem. It should be a cargo subcommand, please.

@jkelleyrtp
Copy link

jkelleyrtp commented Jun 1, 2025

"cargo plus plus"

That's how you kill an ecosystem. It should be a cargo subcommand, please.

wasm-bindgen, wasm-pack, and trunk are not cargo subcommands. cargo cannot run, test, or bench wasm, ios, android projects nor does it properly assemble app bundles. wasm-bindgen is the most used cli in the rust ecosystem and it is not a subcommand.

@n1ght-hunter
Copy link

n1ght-hunter commented Jun 1, 2025

@jkelleyrtp what is it that you actually want?

I understand Dioxus/you put a lot of work into creating subsecond and hot patching and should be referenced etc. (did an amazing job :) )
but currently at least subsecond and the cli required is very closely tied to Dioxus(i.e. source control, release cycle etc).
IMO this is not the best for the rust ecosystem as whole as its makes harder to patch and change as required for the whole ecosystem of crates and also means that the Dioxus-cli is required to use hot reloading which is small subset of the total functionally.

to solve some of these issues it makes sense to me to have a separate source control etc for the pure functionally of hot reloading.
i actually think it might make sense to create an entire github org to handle subsecond and required crates (since it seems to be makeing waves in the rust ecosystem).

i think it would be useful to answer what you were wanting/expecting.
were you wanting all related subsecond to remain under Dioxus and to what extent.
would you be willing to move the subsecond and other required functionality to a separate source control (in or out of DioxusLabs org).

not just extricate our work to put their own name on it.

i dont think anyone wanted to take your work and put their name on it.
in the case of https://github.com/hecrj/cargo-hot/tree/master
its currently very experimental its has 4 commits and doesnt even have a readme.
it currently references your name in the license(did you want somthing else?) and was created for trying out functionally without the full Dioxus cli

@TapGhoul
Copy link

TapGhoul commented Jun 1, 2025

wasm-bindgen, wasm-pack, and trunk are not cargo subcommands. cargo cannot run, test, or bench wasm, ios, android projects nor does it properly assemble app bundles. wasm-bindgen is the most used cli in the rust ecosystem and it is not a subcommand.

@jkelleyrtp I'd argue it still makes sense as a subcommand, even though others aren't. Cargo subcommands are basically the same as git subcommands - they just attach a prefix, and your binary works the same as standalone. The only difference (from a rudimentary check of making one) is that they automatically set some environment variables in addition, specifically:

  • CARGO_HOME - $HOME/.cargo usually
  • RUSTUP_TOOLCHAIN - current target triple
  • SSL_CERT_DIR - in my case, /etc/ssl/certs
  • SSL_CERT_FILE - in my case, /etc/ssl/cert.pem
  • RUST_RECURSION_COUNT - just a general recursion counter
  • RUSTUP_HOME - $HOME/.rustup usually
  • LD_LIBRARY_PATH - it injects the current rust toolchain lib dir
  • CARGO - Full path to the cargo binary for the current active toolchain

as well as adding the actual cargo subcommand name as the first argument.

In the case of the standard dx CLI, it makes sense to be standalone - dioxus is not just a rust tool, and can be initialized via npm too. So requiring it be a cargo subcommand may be a little constraining.
On the flipside, the cargo subcommands do work without cargo, as they are just named as cargo-binname so you can run it as that. For a rust ecosystem tool, I think it makes more sense for it to be a cargo subcommand, if we are trying to make it widely reusable as the dioxus project seems to hope for. The dx cli can just inject what it needs into the argument list when running as a subcommand, assuming that's how you guys would integrate it if it were to be split out.

Many cargo-installed binaries I use don't work as a cargo subcommand, but generally the differentiator between ones that do and ones that don't are if they are specifically about rust code and operating on your actual codebase (with the exception of cargo-install-update, which is a cargo subcommand but doesn't operate on a codebase level - still makes sense to me).
I'd argue that a subsecond CLI tool makes a lot of sense as a cargo subcommand, given the general pattern I've seen.

@hecrj
Copy link

hecrj commented Jun 1, 2025

@jkelleyrtp I am very grateful for all your amazing work; but I don't think you get what open source means.

Even then, I don't think an exploration that is ~8 hours old warrants this reaction. I enjoy exploring on my own and I had no ill intent. In fact, I thought Dioxus could eventually switch to it and join efforts.

I am sorry to disappoint, but I don't need to "reach out" when I am already working right here in the open.

In any case, I am happy to cooperate and join efforts with anyone that would find this tool useful. I am definitely not the right person to maintain it!

@janhohenheim
Copy link
Member Author

janhohenheim commented Jun 1, 2025

Re: cargo subcommand vs own command

The frustrations with cargo's limitations and its glacial development cycle has led this very project to design the Bevy CLI alpha as a cargo replacement / wrapper and not a subcommand.

I think it's worth not immediately dismissing the validity of a cargo v2. As Jon points out, quite a few projects have come to the conclusion that cargo is often simply not enough. The discussion of whether we want to collectively encourage the ecosystem to migrate to a cargo replacement or not is certainly out of scope for this wee issue. For prolonged discussion of this, I suggest moving to a dedicated issue on the Dioxus repo instead.

For Bevy's use-case, the relevant PR is not even merged yet, the feature is experimental, and the Dioxus version it depends on is in alpha. Really, we should be fine with some hoops right now IMO.

@TapGhoul
Copy link

TapGhoul commented Jun 1, 2025

The frustrations with cargo's limitations and its glacial development cycle has led this very project to design the Bevy CLI alpha as a cargo replacement / wrapper and not a subcommand.

@janhohenheim I am kinda curious - what were the limitations found? Do you have a link to a discussion on the discord or here on github about this? I'm unaware of such limitations as I don't tend to work on CLI tools much, so I'm very interested where the limitations have been found.

@janhohenheim
Copy link
Member Author

@BD103 @TimJentzsch ^

@teohhanhui
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Feature A new feature, making something new possible C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Complex Quite challenging from either a design or technical perspective. Ask for help! D-Unsafe Touches with unsafe code in some way S-Needs-Design This issue requires design work to think about how it would best be accomplished X-Blessed Has a large architectural impact or tradeoffs, but the design has been endorsed by decision makers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants