Skip to content
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

[native_assets][resource_identifiers] Deferred loading and assets #55809

Open
Tracked by #50565 ...
dcharkes opened this issue May 22, 2024 · 2 comments
Open
Tracked by #50565 ...

[native_assets][resource_identifiers] Deferred loading and assets #55809

dcharkes opened this issue May 22, 2024 · 2 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends.

Comments

@dcharkes
Copy link
Contributor

@mosuem and I had a bunch of discussions around loading units and native assets.

Tree shaking whole native assets if they're completely unused is kind of a special case of loading units. E.g. the asset doesn't end up in any of the loading units.

One of the main questions is whether we can let the Dart&Flutter SDK do this, or whether this needs to be part of the native_asset_cli protocol.

If assetLoadBytes has a must be const assetId (and @Native already has a const asset id), then we might be able to do it in the SDK and avoid ever having to add loading units to the build and link hook protocols.

If making the assetId being const in loadBytes is too restrictive, we could consider having an AssetReference(String assetId) implements RecordReference which can be sprinkled on methods.

However, if even that turns out to be too restrictive (because some const string arguments are passed to some method, and there is some arbitrary mapping to asset Ids which is easily implemented in build or link hooks), then the loading units should be part of the (build and) link hook protocol.

Currently, the tree-shaking of whole assets must also be implemented by a package author in their link hook. We have an open issue for automatically not bundling it based on the @Native annotations (#52970 (comment)).

@dcharkes
Copy link
Contributor Author

@mosuem suggested that instead of assetLoadBytes with a param mustBeConst, we can have

@Data(String assetId)
external Future<Unint8List> myAssetBytes;

This would fully align it with with how @Native() external FFI calls are working. The assetId is forced to be const.

We would need to see if this covers all the use cases, or whether we do need to provide some way of providing abstraction on top of it.

@mit-mit mit-mit added the area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. label May 22, 2024
@dcharkes
Copy link
Contributor Author

We would need to see if this covers all the use cases, or whether we do need to provide some way of providing abstraction on top of it.

We can enable abstraction by making assetId in the @Data annotation optional and requiring it is a param on the external:

@Data()
external Future<Unint8List> myAssetBytes(String assetId);

Longer explanation: #54003 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends.
Projects
None yet
Development

No branches or pull requests

2 participants