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
import java.nio.ByteBuffer
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) {
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)
basicStandard.setMessageHandler { message, reply -> reply.reply(message) }
val basicBinary = BasicMessageChannel(flutterEngine.dartExecutor, "dev.flutter.echo.basic.binary", BinaryCodec.INSTANCE)
basicBinary.setMessageHandler { message, reply -> run {
val result = ByteBuffer.allocateDirect(message!!.capacity())
result.put(message)
reply.reply(result)
if (byteBufferCache == null) {
byteBufferCache = ByteBuffer.allocateDirect(message!!.capacity())
byteBufferCache!!.put(message)
}
reply.reply(byteBufferCache)
} }
super.configureFlutterEngine(flutterEngine)
}
......
......@@ -14,6 +14,11 @@ import UIKit
GeneratedPluginRegistrant.register(with: self)
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(
name: "dev.flutter.echo.basic.standard", binaryMessenger: registrar.messenger(),
codec: FlutterStandardMessageCodec.sharedInstance())
......
......@@ -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>(
'dev.flutter.echo.basic.standard',
StandardMessageCodec(),
......@@ -129,6 +133,7 @@ Future<void> _runTests() async {
const int numMessages = 2500;
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
resetChannel.send(true);
await _runBasicStandardSmall(basicStandard, 1); // Warmup.
printer.addResult(
description: 'BasicMessageChannel/StandardMessageCodec/Flutter->Host/Small',
......@@ -136,6 +141,7 @@ Future<void> _runTests() async {
unit: 'µs',
name: 'platform_channel_basic_standard_2host_small',
);
resetChannel.send(true);
await _runBasicStandardLarge(basicStandard, largeBuffer, 1); // Warmup.
printer.addResult(
description: 'BasicMessageChannel/StandardMessageCodec/Flutter->Host/Large',
......@@ -144,6 +150,7 @@ Future<void> _runTests() async {
unit: 'µs',
name: 'platform_channel_basic_standard_2host_large',
);
resetChannel.send(true);
await _runBasicBinary(basicBinary, largeBufferBytes, 1); // Warmup.
printer.addResult(
description: 'BasicMessageChannel/BinaryCodec/Flutter->Host/Large',
......@@ -151,6 +158,7 @@ Future<void> _runTests() async {
unit: 'µs',
name: 'platform_channel_basic_binary_2host_large',
);
resetChannel.send(true);
await _runBasicBinary(basicBinary, oneMB, 1); // Warmup.
printer.addResult(
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