[native_assets] Hot restart native libs #55850
Labels
area-native-interop
Used for native interop related issues, including FFI.
library-ffi
type-enhancement
A request for a change that isn't a bug
Milestone
We should consider trying to support "hot restart" for native code.
The native code would need to be bundled with dylibs (not statically linked).
We could unload all dylibs loaded by
@Native
s and purging caches for resolved natives.For Dart in JIT mode this should be enough, as the dylibs will just be on disk. (Windows might be problematic if as dylibs cannot be deleted while in use.)
For Flutter in JIT mode we'd need some Flutter specific support for copying the dylibs to the right place (and possibly signing them).
Hot reload doesn't make sense for dylibs, because the memory of the dylib cannot be migrated (the native languages don't have the same support as Dart).
Hot restarting native libs when doing a Dart hot reload seems to be a bad idea, due to the Dart and native state getting out of sync.
We'd need to decide whether we'd always want hot restart native libs on hot restarting Dart, or whether it should be a different command. I think hot restarting both together would be better than hot restarting one. Hot restarting only native code means things like native finalizers in the Dart heap would still exist. (Due to native finalizers being run on isolate shutdown, we should probably shut down Dart isolates first, then unload the dylibs and then start a Dart isolate again.)
Thanks for the suggestion @fzyzcjy! 🙏
Related issues:
The text was updated successfully, but these errors were encountered: