Skip to content

[native_assets] Hot restart native libs #55850

Open
@dcharkes

Description

@dcharkes

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 @Natives 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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-native-interopUsed for native interop related issues, including FFI.library-ffitype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions