Unverified Commit b011ea54 authored by Gary Qian's avatar Gary Qian Committed by GitHub

Pass _caretPrototype to prevent cache miss (#46720)

parent 3fe66688
......@@ -9,3 +9,4 @@ const String kPostBackdropFilterRouteName = '/post_backdrop_filter';
const String kSimpleAnimationRouteName = '/simple_animation';
const String kPictureCacheRouteName = '/picture_cache';
const String kLargeImagesRouteName = '/large_images';
const String kTextRouteName = '/text';
......@@ -12,6 +12,7 @@ import 'src/cubic_bezier.dart';
import 'src/cull_opacity.dart';
import 'src/post_backdrop_filter.dart';
import 'src/simple_animation.dart';
import 'src/text.dart';
const String kMacrobenchmarks ='Macrobenchmarks';
......@@ -34,6 +35,7 @@ class MacrobenchmarksApp extends StatelessWidget {
kSimpleAnimationRouteName: (BuildContext conttext) => SimpleAnimationPage(),
kPictureCacheRouteName: (BuildContext context) => PictureCachePage(),
kLargeImagesRouteName: (BuildContext context) => LargeImagesPage(),
kTextRouteName: (BuildContext context) => TextPage(),
},
);
}
......@@ -97,6 +99,13 @@ class HomePage extends StatelessWidget {
Navigator.pushNamed(context, kLargeImagesRouteName);
},
),
RaisedButton(
key: const Key(kTextRouteName),
child: const Text('Text'),
onPressed: () {
Navigator.pushNamed(context, kTextRouteName);
},
),
],
),
);
......
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
class TextPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Container(
width: 200,
height: 100,
child: const TextField(
key: Key('basic-textfield'),
),
),
],
);
}
}
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter_driver/driver_extension.dart';
import 'package:macrobenchmarks/main.dart' as app;
void main() {
enableFlutterDriverExtension();
app.main();
}
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter_driver/flutter_driver.dart';
import 'package:macrobenchmarks/common.dart';
import 'util.dart';
void main() {
macroPerfTest(
'textfield_perf',
kTextRouteName,
driverOps: (FlutterDriver driver) async {
final SerializableFinder textfield = find.byValueKey('basic-textfield');
driver.tap(textfield);
// Caret should be cached, so repeated blinking should not require recompute.
await Future<void>.delayed(const Duration(milliseconds: 5000));
},
);
}
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'package:flutter_devicelab/tasks/perf_tests.dart';
import 'package:flutter_devicelab/framework/adb.dart';
import 'package:flutter_devicelab/framework/framework.dart';
Future<void> main() async {
deviceOperatingSystem = DeviceOperatingSystem.android;
await task(createTextfieldPerfTest());
}
......@@ -156,6 +156,14 @@ TaskFunction createBasicMaterialCompileTest() {
};
}
TaskFunction createTextfieldPerfTest() {
return PerfTest(
'${flutterDirectory.path}/dev/benchmarks/macrobenchmarks',
'test_driver/textfield_perf.dart',
'textfield_perf',
).run;
}
/// Measure application startup performance.
class StartupTest {
......
......@@ -170,6 +170,8 @@ class TextPainter {
void markNeedsLayout() {
_paragraph = null;
_needsLayout = true;
_previousCaretPosition = null;
_previousCaretPrototype = null;
}
/// The (potentially styled) text to paint.
......
......@@ -365,7 +365,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
final Offset startOffset = _textPainter.getOffsetForCaret(
TextPosition(offset: _selection.start, affinity: _selection.affinity),
Rect.zero,
_caretPrototype,
);
// TODO(justinmc): https://github.com/flutter/flutter/issues/31495
// Check if the selection is visible with an approximation because a
......@@ -381,7 +381,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
final Offset endOffset = _textPainter.getOffsetForCaret(
TextPosition(offset: _selection.end, affinity: _selection.affinity),
Rect.zero,
_caretPrototype,
);
_selectionEndInViewport.value = visibleRegion
.inflate(visibleRegionSlop)
......
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