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

performance question, For example, there are 10 NSString parameters #23

Open
xiushaomin opened this issue Sep 10, 2020 · 5 comments
Open
Assignees
Labels
question Further information is requested

Comments

@xiushaomin
Copy link

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?

@xiushaomin xiushaomin changed the title Performance question performance question Sep 10, 2020
@xiushaomin xiushaomin changed the title performance question performance question, For example, there are 10 NSString parameters Sep 10, 2020
@yulingtianxia yulingtianxia self-assigned this Sep 11, 2020
@yulingtianxia yulingtianxia added the question Further information is requested label Sep 11, 2020
@yulingtianxia
Copy link
Member

See this article: http://yulingtianxia.com/blog/2019/11/28/DartObjC-Design/

We should do more tests.

@xiushaomin
Copy link
Author

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}");

@yulingtianxia
Copy link
Member

yulingtianxia commented Sep 11, 2020

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: #22

@xiushaomin
Copy link
Author

ok,thanks!learned a lot in this project~

@yulingtianxia
Copy link
Member

ok,thanks!learned a lot in this project~

Thank you for using DartNative. We are still developing and optimizing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants