native icon indicating copy to clipboard operation
native copied to clipboard

Benchmarks for different coding patterns using dart:ffi

Open vaind opened this issue 2 years ago • 2 comments
trafficstars

Similar to https://github.com/dart-lang/native/issues/718 - it would be nice to have benchmarks to consult for various some non-trivial yet pretty common cases.

For example, what is the performance of an FFI call that returns a fixed size map (a couple of items, some layers) compared to method channels. This should be implemented in all languages, i.e. for Objective-C, that means converting from NSDictionary (or accessing items), to actually compare that to a real-world API that returns a dictionary as its output.

The jnigen issue linked above gives some thoughts on how these benchmarks could be implemented & integrated.

vaind avatar Sep 18 '23 15:09 vaind

Feel free to contribute some. 😄

I'm not sure if benchmarks targeting C should be considered FFIgen related, rather they would be dart:ffi related. FFIgen does not make any architectural decisions or generate code which is executed (JNIgen does). So I think these benchmarks would fit better in the Dart SDK. (Note we already have a bunch of FFI benchmarks in the SDK, for example https://github.com/dart-lang/sdk/tree/main/benchmarks/FfiMemory/dart. However, I don't believe we target any high level concepts.)

Benchmarks targeting Objective-C are FFIgen related, because FFIgen makes some decisions about how to invoke things. Especially with blocks.

If the benchmarks should be together with their method channel counterparts, it becomes a Flutter-specific comparison, and benchmarks do not belong in the Dart SDK. Then maybe they should be contributed to the Flutter repo instead. (I'm not very familiar with the benchmarks over there.)

dcharkes avatar Sep 18 '23 15:09 dcharkes

Benchmarks that benchmark individual dart:ffi features are in https://github.com/dart-lang/sdk/tree/main/benchmarks.

Benchmarks that benchmark how long it takes to run FFIgen code generator can live on this repo in pkgs/ffigen/benchmark.

This issue tracks benchmarks for coding patterns that use dart:ffi (and likely FFIgen for convenience). They probably shouldn't live in either of the two above mentioned places. Maybe we should introduce a pkgs/ffi_coding_patterns/benchmark or pkgs/interop_examples/benchmark or something similar to accumulate a list of coding examples and benchmarks of their performance. Alternatively, this could live on a separate repo completely. It doesn't have to be owned by the Dart team.

dcharkes avatar Aug 15 '24 07:08 dcharkes