From fa33c76e01ac2d16f623c1eff213195839fabd73 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Fri, 18 Sep 2020 12:32:02 -0700 Subject: [PATCH] set old_gen_heap_size to half of available memory on iOS (#20472) --- ci/licenses_golden/licenses_flutter | 1 + common/constants.h | 7 +++++++ flow/raster_cache.cc | 8 ++++---- .../darwin/ios/framework/Source/FlutterDartProject.mm | 11 +++++++++++ .../ios/framework/Source/FlutterDartProjectTest.mm | 10 ++++++++++ 5 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 common/constants.h diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 5096ca7cdec..2211299487a 100755 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -19,6 +19,7 @@ FILE: ../../../flutter/assets/directory_asset_bundle.cc FILE: ../../../flutter/assets/directory_asset_bundle.h FILE: ../../../flutter/benchmarking/benchmarking.cc FILE: ../../../flutter/benchmarking/benchmarking.h +FILE: ../../../flutter/common/constants.h FILE: ../../../flutter/common/exported_symbols.sym FILE: ../../../flutter/common/settings.cc FILE: ../../../flutter/common/settings.h diff --git a/common/constants.h b/common/constants.h new file mode 100644 index 00000000000..50b0f91e848 --- /dev/null +++ b/common/constants.h @@ -0,0 +1,7 @@ +// 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. + +namespace flutter { +constexpr double kMegaByteSizeInBytes = (1 << 20); +} // namespace flutter diff --git a/flow/raster_cache.cc b/flow/raster_cache.cc index 72f55bc7e3b..6db5a8103f3 100644 --- a/flow/raster_cache.cc +++ b/flow/raster_cache.cc @@ -6,6 +6,7 @@ #include +#include "flutter/common/constants.h" #include "flutter/flow/layers/layer.h" #include "flutter/flow/paint_utils.h" #include "flutter/fml/logging.h" @@ -298,12 +299,11 @@ void RasterCache::SetCheckboardCacheImages(bool checkerboard) { void RasterCache::TraceStatsToTimeline() const { #if !FLUTTER_RELEASE - constexpr double kMegaBytes = (1 << 20); FML_TRACE_COUNTER("flutter", "RasterCache", reinterpret_cast(this), "LayerCount", layer_cache_.size(), "LayerMBytes", - EstimateLayerCacheByteSize() / kMegaBytes, "PictureCount", - picture_cache_.size(), "PictureMBytes", - EstimatePictureCacheByteSize() / kMegaBytes); + EstimateLayerCacheByteSize() / kMegaByteSizeInBytes, + "PictureCount", picture_cache_.size(), "PictureMBytes", + EstimatePictureCacheByteSize() / kMegaByteSizeInBytes); #endif // !FLUTTER_RELEASE } diff --git a/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm b/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm index 62b9c23c4a0..b87fde573c3 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm @@ -6,6 +6,7 @@ #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject_Internal.h" +#include "flutter/common/constants.h" #include "flutter/common/task_runners.h" #include "flutter/fml/mapping.h" #include "flutter/fml/message_loop.h" @@ -151,6 +152,16 @@ static flutter::Settings DefaultSettingsForProcess(NSBundle* bundle = nil) { make_mapping_callback(kPlatformStrongDill, kPlatformStrongDillSize); #endif // FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG + // If we even support setting this e.g. from the command line or the plist, + // we should let the user override it. + // Otherwise, we want to set this to a value that will avoid having the OS + // kill us. On most iOS devices, that happens somewhere near half + // the available memory. + // The VM expects this value to be in megabytes. + if (settings.old_gen_heap_size <= 0) { + settings.old_gen_heap_size = std::round([NSProcessInfo processInfo].physicalMemory * .48 / + flutter::kMegaByteSizeInBytes); + } return settings; } diff --git a/shell/platform/darwin/ios/framework/Source/FlutterDartProjectTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterDartProjectTest.mm index 0a3dff7db40..56cc57c2041 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterDartProjectTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterDartProjectTest.mm @@ -2,8 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#import #import +#include "flutter/common/constants.h" +#include "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h" #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject_Internal.h" FLUTTER_ASSERT_ARC @@ -19,6 +22,13 @@ FLUTTER_ASSERT_ARC - (void)tearDown { } +- (void)testOldGenHeapSizeSetting { + FlutterDartProject* project = [[FlutterDartProject alloc] init]; + int64_t old_gen_heap_size = + std::round([NSProcessInfo processInfo].physicalMemory * .48 / flutter::kMegaByteSizeInBytes); + XCTAssertEqual(project.settings.old_gen_heap_size, old_gen_heap_size); +} + - (void)testMainBundleSettingsAreCorrectlyParsed { NSBundle* mainBundle = [NSBundle mainBundle]; NSDictionary* appTransportSecurity =