Skip to content

Commit

Permalink
Add option to enable serial GC (flutter#30975)
Browse files Browse the repository at this point in the history
* Roll Dart SDK from e256855 to a3b62f3 (4 revisions) (flutter#21809)

* Roll Dart SDK from e655b9a to b58cfe5 (1 revision) (flutter#21920)

* Roll Dart SDK from fc82eee to 8be6a08 (1 revision) (flutter#22005)

* Roll Dart SDK from fe12b05 to a188781 (1 revision) (flutter#22379)

* Roll Skia from 95b5fb9 to 68ac3b9 (17 revisions) (flutter#22713)

* Roll Dart SDK from 2c74e62 to f9760fc (5 revisions) (flutter#22881)

* Roll Dart SDK from 68d1c75 to f166571 (1 revision) (flutter#23056)

* Roll Dart SDK from 970d74c to fd72dbb (1 revision) (flutter#23820)

* Trigger an engine build to re-open the tree (flutter#26056)

This commit is empty and simply triggers a new build to open the tree.

Commit 106963e was re-built after a
succesful build; upload to the cloud storage bin failed.

* Roll Skia from d9a7c5953df3 to 827bb729a84d (2 revisions) (flutter#26096)

* Roll Dart SDK from d616108 to a527411 (0 revision) (flutter#26156)

* Roll Dart SDK from bb9d96f to 7250fd6 (0 revision) (flutter#26374)

* Roll Dart SDK from 202c42e to 2e9c430 (1 revision) (flutter#26578)

* Roll buildroot to 275038b (flutter#26945)

* [test] empty commit (flutter#27599)

https://flutter-review.googlesource.com/c/infra/+/15660

* Roll Dart SDK from e141400 to 6860708 (1 revision) (flutter#27620)

* Empty commit to apply latest LUCI config (flutter#27767)

* Roll Dart SDK from 3b11f88 to 976f160 (3 revisions) (flutter#29436)

* Empty commit to fix main tree status (flutter#29760)

* Add option to enable serial GC
This option can be used to avoid thread contention issues for the UI thread when running on low power devices with limited number of cores.

* Fix format.

* Added test.

* Add build rule.

* Address review comments.

Co-authored-by: skia-flutter-autoroll <[email protected]>
Co-authored-by: Chris Bracken <[email protected]>
Co-authored-by: Casey Hillers <[email protected]>
  • Loading branch information
4 people authored Jan 26, 2022
1 parent 3408278 commit 6031924
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions common/settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ std::string Settings::ToString() const {
stream << "endless_trace_buffer: " << endless_trace_buffer << std::endl;
stream << "enable_dart_profiling: " << enable_dart_profiling << std::endl;
stream << "disable_dart_asserts: " << disable_dart_asserts << std::endl;
stream << "enable_serial_gc: " << enable_serial_gc << std::endl;
stream << "enable_observatory: " << enable_observatory << std::endl;
stream << "enable_observatory_publication: " << enable_observatory_publication
<< std::endl;
Expand Down
1 change: 1 addition & 0 deletions common/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ struct Settings {
bool endless_trace_buffer = false;
bool enable_dart_profiling = false;
bool disable_dart_asserts = false;
bool enable_serial_gc = false;

// Whether embedder only allows secure connections.
bool may_insecurely_connect_to_all_domains = true;
Expand Down
17 changes: 17 additions & 0 deletions runtime/dart_vm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ static const char* kDartLanguageArgs[] = {

static const char* kDartPrecompilationArgs[] = {"--precompilation"};

static const char* kSerialGCArgs[] = {
// clang-format off
"--concurrent_mark=false",
"--concurrent_sweep=false",
"--compactor_tasks=1",
"--scavenger_tasks=0",
"--marker_tasks=0",
// clang-format on
};

FML_ALLOW_UNUSED_TYPE
static const char* kDartWriteProtectCodeArgs[] = {
"--no_write_protect_code",
Expand Down Expand Up @@ -358,6 +368,13 @@ DartVM::DartVM(std::shared_ptr<const DartVMData> vm_data,
PushBackAll(&args, kDartAssertArgs, fml::size(kDartAssertArgs));
}

// On low power devices with lesser number of cores, using concurrent
// marking or sweeping causes contention for the UI thread leading to
// Jank, this option can be used to turn off all concurrent GC activities.
if (settings_.enable_serial_gc) {
PushBackAll(&args, kSerialGCArgs, fml::size(kSerialGCArgs));
}

if (settings_.start_paused) {
PushBackAll(&args, kDartStartPausedArgs, fml::size(kDartStartPausedArgs));
}
Expand Down
3 changes: 3 additions & 0 deletions shell/common/switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,9 @@ Settings SettingsFromCommandLine(const fml::CommandLine& command_line) {
settings.trace_startup =
command_line.HasOption(FlagForSwitch(Switch::TraceStartup));

settings.enable_serial_gc =
command_line.HasOption(FlagForSwitch(Switch::EnableSerialGC));

#if !FLUTTER_RELEASE
settings.trace_skia = true;

Expand Down
6 changes: 6 additions & 0 deletions shell/common/switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ DEF_SWITCH(DisableDartAsserts,
"disabled. This flag may be specified if the user wishes to run "
"with assertions disabled in the debug product mode (i.e. with JIT "
"or DBC).")
DEF_SWITCH(EnableSerialGC,
"enable-serial-gc",
"On low power devices with low core counts, running concurrent "
"GC tasks on threads can cause them to contend with the UI thread "
"which could potentially lead to jank. This option turns off all "
"concurrent GC activities")
DEF_SWITCH(DisallowInsecureConnections,
"disallow-insecure-connections",
"By default, dart:io allows all socket connections. If this switch "
Expand Down
1 change: 1 addition & 0 deletions testing/dart/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ tests = [
"platform_view_test.dart",
"plugin_utilities_test.dart",
"semantics_test.dart",
"serial_gc_test.dart",
"spirv_exception_test.dart",
"task_order_test.dart",
"text_test.dart",
Expand Down
17 changes: 17 additions & 0 deletions testing/dart/serial_gc_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2013 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.

// FlutterTesterOptions=--enable-serial-gc

import 'package:litetest/litetest.dart';

void main() {
test('Serial GC option test ', () async {
bool threw = false;
for (int i = 0; i < 100; i++) {
var a = <int>[100];
}
expect(threw, false);
});
}

0 comments on commit 6031924

Please sign in to comment.