Skip to content

How to pass huge objects across isolates and/or ffi, without huge memory and cpu footprint? #1862

Closed
@fzyzcjy

Description

@fzyzcjy

Hi thanks for wonderful dart and flutter!

Scenario: My app have some image processing features in C++, which takes 1s (for example) to compute the output image from the input image. Since I do not want to block the main isolate (otherwise the ui will freeze), I do the following:

Main Isolate <-----SendPort----> Worker Isolate <----FFI----> C++ Code

However, you know images are quite huge, say, 30MB per image. By doing this, one image will have at least 3 copies! The source image is in main isolate, then using SendPort, it is copied (!) to the worker isolate, then again copied (!) to c++ native code. Thus, we use at least 90MB memory when we can simply use 30MB memory, let alone the wasted time for memory copying.

Is there any ways? Thank you so much!

Metadata

Metadata

Assignees

No one assigned

    Labels

    requestRequests to resolve a particular developer problem

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions