Unverified Commit ade6e1f9 authored by gaaclarke's avatar gaaclarke Committed by GitHub

Made the android platform channel benchmarks comparable to iOS (#83110)

parent c500a062
...@@ -12,15 +12,24 @@ import io.flutter.plugin.common.StandardMessageCodec ...@@ -12,15 +12,24 @@ import io.flutter.plugin.common.StandardMessageCodec
import java.nio.ByteBuffer import java.nio.ByteBuffer
class MainActivity: FlutterActivity() { class MainActivity: FlutterActivity() {
// We allow for the caching of a response in the binary channel case since
// the reply requires a direct buffer, but the input is not a direct buffer.
// We can't directly send the input back to the reply currently.
private var byteBufferCache : ByteBuffer? = null
override fun configureFlutterEngine(flutterEngine: FlutterEngine) { override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
val reset = BasicMessageChannel(flutterEngine.dartExecutor, "dev.flutter.echo.reset", StandardMessageCodec.INSTANCE)
reset.setMessageHandler { message, reply -> run {
byteBufferCache = null
} }
val basicStandard = BasicMessageChannel(flutterEngine.dartExecutor, "dev.flutter.echo.basic.standard", StandardMessageCodec.INSTANCE) val basicStandard = BasicMessageChannel(flutterEngine.dartExecutor, "dev.flutter.echo.basic.standard", StandardMessageCodec.INSTANCE)
basicStandard.setMessageHandler { message, reply -> reply.reply(message) } basicStandard.setMessageHandler { message, reply -> reply.reply(message) }
val basicBinary = BasicMessageChannel(flutterEngine.dartExecutor, "dev.flutter.echo.basic.binary", BinaryCodec.INSTANCE) val basicBinary = BasicMessageChannel(flutterEngine.dartExecutor, "dev.flutter.echo.basic.binary", BinaryCodec.INSTANCE)
basicBinary.setMessageHandler { message, reply -> run { basicBinary.setMessageHandler { message, reply -> run {
val result = ByteBuffer.allocateDirect(message!!.capacity()) if (byteBufferCache == null) {
result.put(message) byteBufferCache = ByteBuffer.allocateDirect(message!!.capacity())
reply.reply(result) byteBufferCache!!.put(message)
}
reply.reply(byteBufferCache)
} } } }
super.configureFlutterEngine(flutterEngine) super.configureFlutterEngine(flutterEngine)
} }
......
...@@ -14,6 +14,11 @@ import UIKit ...@@ -14,6 +14,11 @@ import UIKit
GeneratedPluginRegistrant.register(with: self) GeneratedPluginRegistrant.register(with: self)
let registrar = self.registrar(forPlugin: "Echo")! let registrar = self.registrar(forPlugin: "Echo")!
let reset = FlutterBasicMessageChannel(
name: "dev.flutter.echo.reset", binaryMessenger: registrar.messenger())
reset.setMessageHandler { (input, reply) in
// noop
}
let basicStandard = FlutterBasicMessageChannel( let basicStandard = FlutterBasicMessageChannel(
name: "dev.flutter.echo.basic.standard", binaryMessenger: registrar.messenger(), name: "dev.flutter.echo.basic.standard", binaryMessenger: registrar.messenger(),
codec: FlutterStandardMessageCodec.sharedInstance()) codec: FlutterStandardMessageCodec.sharedInstance())
......
...@@ -108,6 +108,10 @@ Future<void> _runTests() async { ...@@ -108,6 +108,10 @@ Future<void> _runTests() async {
); );
} }
const BasicMessageChannel<Object> resetChannel = BasicMessageChannel<Object>(
'dev.flutter.echo.reset',
StandardMessageCodec(),
);
const BasicMessageChannel<Object> basicStandard = BasicMessageChannel<Object>( const BasicMessageChannel<Object> basicStandard = BasicMessageChannel<Object>(
'dev.flutter.echo.basic.standard', 'dev.flutter.echo.basic.standard',
StandardMessageCodec(), StandardMessageCodec(),
...@@ -129,6 +133,7 @@ Future<void> _runTests() async { ...@@ -129,6 +133,7 @@ Future<void> _runTests() async {
const int numMessages = 2500; const int numMessages = 2500;
final BenchmarkResultPrinter printer = BenchmarkResultPrinter(); final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
resetChannel.send(true);
await _runBasicStandardSmall(basicStandard, 1); // Warmup. await _runBasicStandardSmall(basicStandard, 1); // Warmup.
printer.addResult( printer.addResult(
description: 'BasicMessageChannel/StandardMessageCodec/Flutter->Host/Small', description: 'BasicMessageChannel/StandardMessageCodec/Flutter->Host/Small',
...@@ -136,6 +141,7 @@ Future<void> _runTests() async { ...@@ -136,6 +141,7 @@ Future<void> _runTests() async {
unit: 'µs', unit: 'µs',
name: 'platform_channel_basic_standard_2host_small', name: 'platform_channel_basic_standard_2host_small',
); );
resetChannel.send(true);
await _runBasicStandardLarge(basicStandard, largeBuffer, 1); // Warmup. await _runBasicStandardLarge(basicStandard, largeBuffer, 1); // Warmup.
printer.addResult( printer.addResult(
description: 'BasicMessageChannel/StandardMessageCodec/Flutter->Host/Large', description: 'BasicMessageChannel/StandardMessageCodec/Flutter->Host/Large',
...@@ -144,6 +150,7 @@ Future<void> _runTests() async { ...@@ -144,6 +150,7 @@ Future<void> _runTests() async {
unit: 'µs', unit: 'µs',
name: 'platform_channel_basic_standard_2host_large', name: 'platform_channel_basic_standard_2host_large',
); );
resetChannel.send(true);
await _runBasicBinary(basicBinary, largeBufferBytes, 1); // Warmup. await _runBasicBinary(basicBinary, largeBufferBytes, 1); // Warmup.
printer.addResult( printer.addResult(
description: 'BasicMessageChannel/BinaryCodec/Flutter->Host/Large', description: 'BasicMessageChannel/BinaryCodec/Flutter->Host/Large',
...@@ -151,6 +158,7 @@ Future<void> _runTests() async { ...@@ -151,6 +158,7 @@ Future<void> _runTests() async {
unit: 'µs', unit: 'µs',
name: 'platform_channel_basic_binary_2host_large', name: 'platform_channel_basic_binary_2host_large',
); );
resetChannel.send(true);
await _runBasicBinary(basicBinary, oneMB, 1); // Warmup. await _runBasicBinary(basicBinary, oneMB, 1); // Warmup.
printer.addResult( printer.addResult(
description: 'BasicMessageChannel/BinaryCodec/Flutter->Host/1MB', description: 'BasicMessageChannel/BinaryCodec/Flutter->Host/1MB',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment