From 925f3eee66f14cd8d517cee745ee432982adcfbe Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Mon, 6 Nov 2023 11:49:15 -0800 Subject: [PATCH] [benchmarks] disable partial repaint for multiple backdrop blur iOS macrobenchmarks. (#137902) Partial repaint is too effective, and we'd like to be able to measure performance without carefully structuring the benchmarks. For example, right now partial repaint is culling any blurs in the multibackdrop case, which we should be using to track https://github.com/flutter/flutter/issues/132735 --- dev/devicelab/lib/tasks/perf_tests.dart | 94 ++++++++++++++++++++++--- 1 file changed, 86 insertions(+), 8 deletions(-) diff --git a/dev/devicelab/lib/tasks/perf_tests.dart b/dev/devicelab/lib/tasks/perf_tests.dart index ba146880d4c3..59b35ff85127 100644 --- a/dev/devicelab/lib/tasks/perf_tests.dart +++ b/dev/devicelab/lib/tasks/perf_tests.dart @@ -143,6 +143,7 @@ TaskFunction createBackdropFilterPerfTest({ testDriver: 'test_driver/backdrop_filter_perf_test.dart', saveTraceFile: true, enableImpeller: enableImpeller, + disablePartialRepaint: true, ).run; } @@ -767,6 +768,51 @@ Map _average(List> results, int iterations return tally; } +/// Opens the file at testDirectory + 'ios/Runner/Info.plist' +/// and adds the following entry to the application. +/// +/// +void _disablePartialRepaint(String testDirectory) { + final String manifestPath = path.join( + testDirectory, 'ios', 'Runner', 'Info.plist'); + final File file = File(manifestPath); + + if (!file.existsSync()) { + throw Exception('Info.plist not found at $manifestPath'); + } + + final String xmlStr = file.readAsStringSync(); + final XmlDocument xmlDoc = XmlDocument.parse(xmlStr); + final List<(String, String)> keyPairs = <(String, String)>[ + ('FLTDisablePartialRepaint', 'true'), + ]; + + final XmlElement applicationNode = + xmlDoc.findAllElements('dict').first; + + // Check if the meta-data node already exists. + for (final (String key, String value) in keyPairs) { + applicationNode.children.add(XmlElement(XmlName('key'), [], [ + XmlText(key) + ], false)); + applicationNode.children.add(XmlElement(XmlName(value))); + } + + file.writeAsStringSync(xmlDoc.toXmlString(pretty: true, indent: ' ')); +} + +Future _resetPlist(String testDirectory) async { + final String manifestPath = path.join( + testDirectory, 'ios', 'Runner', 'Info.plist'); + final File file = File(manifestPath); + + if (!file.existsSync()) { + throw Exception('Info.plist not found at $manifestPath'); + } + + await exec('git', ['checkout', file.path]); +} + /// Opens the file at testDirectory + 'android/app/src/main/AndroidManifest.xml' /// and adds the following entry to the application. /// Function()? manifestReset; - if (forceOpenGLES ?? false) { - assert(enableImpeller!); - _addOpenGLESToManifest(testDirectory); - manifestReset = () => _resetManifest(testDirectory); + bool changedPlist = false; + bool changedManifest = false; + + Future resetManifest() async { + if (!changedManifest) { + return; + } + try { + await _resetManifest(testDirectory); + } catch (err) { + print('Caught exception while trying to reset AndroidManifest: $err'); + } + } + + Future resetPlist() async { + if (!changedPlist) { + return; + } + try { + await _resetPlist(testDirectory); + } catch (err) { + print('Caught exception while trying to reset Info.plist: $err'); + } } try { + if (forceOpenGLES ?? false) { + assert(enableImpeller!); + changedManifest = true; + _addOpenGLESToManifest(testDirectory); + } + if (disablePartialRepaint) { + changedPlist = true; + _disablePartialRepaint(testDirectory); + } + final List options = [ if (localEngine != null) ...['--local-engine', localEngine], if (localEngineHost != null) ...[ @@ -1278,9 +1357,8 @@ class PerfTest { await flutter('drive', options: options); } } finally { - if (manifestReset != null) { - await manifestReset(); - } + await resetManifest(); + await resetPlist(); } final Map data = json.decode(