Open xiushaomin opened 3 years ago
See this article: http://yulingtianxia.com/blog/2019/11/28/DartObjC-Design/
We should do more tests.
because I want to get some native information through methodchannel before runApp(), but methodchannel has some problems, so I am also looking at ffi-related methods. I read your article that the performance has been greatly improved. I think the performance problem of methodchannel should be Is it the encode/decode byteDate and match to the channel?
I think dart-native create objects is also very performance consuming? The following is my test dart-native code, when the parameter increases, the performance decreases.
class RealChannel {
static const MethodChannel _channel =
const MethodChannel('dart_native');
static Future<String> get platformVersion async {
final String version = await _channel.invokeMethod('getPlatformVersion',["xxxx", 'xxxxx', 'xxxxx', 'xxxxx', 'xxxxx']);
return version;
}
}
final time = DateTime.now().millisecondsSinceEpoch;
for (int i = 0; i < 10000; i++) {
final value = await RealChannel.platformVersion;
print(value);
}
/// 4568ms
print("------------ channel ${DateTime.now().millisecondsSinceEpoch - time}");
final time2 = DateTime.now().millisecondsSinceEpoch;
for (int i = 0; i < 10000; i++) {
stub.fooCompletion('xxx', 'xxxx', 'xxxxxx', 'xxxxxx', (NSString value) {
print(value.raw);
});
}
/// 5768ms
print("------------ native ${DateTime.now().millisecondsSinceEpoch - time2}");
final time3 = DateTime.now().millisecondsSinceEpoch;
for (int i = 0; i < 10000; i++) {
stub.fooCompletion1((NSString value) {
print(value.raw);
});
}
/// 3639ms
print("------------ native2 ${DateTime.now().millisecondsSinceEpoch - time3}");
Converting a Dart String
to a NSString
is time-consuming. This happens in both Channel and DartNative. We are trying to optimize it. See this issue: https://github.com/dart-native/dart_native/issues/22
ok,thanks!learned a lot in this project~
ok,thanks!learned a lot in this project~
Thank you for using DartNative. We are still developing and optimizing.
When there are many parameters and there is also a callback, multiple parameter objects and block objects are created every time the method is called, so is it really faster than the method channel? do you have a test?