jerel / membrane

Membrane is an opinionated crate that generates a Dart package from a Rust library. Extremely fast performance with strict typing and zero copy returns over the FFI boundary via bincode.
Apache License 2.0
88 stars 12 forks source link

Comparison between membrane and flutter_rust_bridge #13

Open xD0135 opened 2 years ago

xD0135 commented 2 years ago

Hi, is it possible to provide a high-level comparison between membrane and https://github.com/fzyzcjy/flutter_rust_bridge?

jerel commented 2 years ago

Sure, happy to try. First, from what I can tell both projects were initially written in private repos without knowledge of the other. When we began working on membrane in late 2020 or early 2021 there were no other end to end Rust <> Flutter FFI tools as far as I know. When I contributed the ZeroCopyBuffer feature back to the allo_isolate package one of my co-workers noticed that a newly open sourced project called flutter_rust_bridge had pulled the feature in as well and was trending on Reddit. All this to say... as far as I know neither project was created to "fix" a deficiency in the other. They are just different implementations and probably have slightly different priorities.

One of the first priorities of membrane is UI performance on the Flutter side, the second goal is developer ergonomics. We did benchmarking of various approaches and found that using a zero copy approach with bincode was extremely fast and stable resulting in no frame drops during high data throughput. If you're not familiar with bincode, it is a serialization protocol that is extremely lightweight as it only encodes the data as opposed to also encoding schema information. Since we control the code on both sides of the FFI boundary we can use this high performance schema-less approach and safely access/free it from Dart using the VM's DartNativeExternalTypedData.

From what I can see these are some of the differences between the two projects: