未验证 提交 fa33c76e 编写于 作者: D Dan Field 提交者: GitHub

set old_gen_heap_size to half of available memory on iOS (#20472)

上级 aec855d3
...@@ -19,6 +19,7 @@ FILE: ../../../flutter/assets/directory_asset_bundle.cc ...@@ -19,6 +19,7 @@ FILE: ../../../flutter/assets/directory_asset_bundle.cc
FILE: ../../../flutter/assets/directory_asset_bundle.h FILE: ../../../flutter/assets/directory_asset_bundle.h
FILE: ../../../flutter/benchmarking/benchmarking.cc FILE: ../../../flutter/benchmarking/benchmarking.cc
FILE: ../../../flutter/benchmarking/benchmarking.h FILE: ../../../flutter/benchmarking/benchmarking.h
FILE: ../../../flutter/common/constants.h
FILE: ../../../flutter/common/exported_symbols.sym FILE: ../../../flutter/common/exported_symbols.sym
FILE: ../../../flutter/common/settings.cc FILE: ../../../flutter/common/settings.cc
FILE: ../../../flutter/common/settings.h FILE: ../../../flutter/common/settings.h
......
// 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
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <vector> #include <vector>
#include "flutter/common/constants.h"
#include "flutter/flow/layers/layer.h" #include "flutter/flow/layers/layer.h"
#include "flutter/flow/paint_utils.h" #include "flutter/flow/paint_utils.h"
#include "flutter/fml/logging.h" #include "flutter/fml/logging.h"
...@@ -298,12 +299,11 @@ void RasterCache::SetCheckboardCacheImages(bool checkerboard) { ...@@ -298,12 +299,11 @@ void RasterCache::SetCheckboardCacheImages(bool checkerboard) {
void RasterCache::TraceStatsToTimeline() const { void RasterCache::TraceStatsToTimeline() const {
#if !FLUTTER_RELEASE #if !FLUTTER_RELEASE
constexpr double kMegaBytes = (1 << 20);
FML_TRACE_COUNTER("flutter", "RasterCache", reinterpret_cast<int64_t>(this), FML_TRACE_COUNTER("flutter", "RasterCache", reinterpret_cast<int64_t>(this),
"LayerCount", layer_cache_.size(), "LayerMBytes", "LayerCount", layer_cache_.size(), "LayerMBytes",
EstimateLayerCacheByteSize() / kMegaBytes, "PictureCount", EstimateLayerCacheByteSize() / kMegaByteSizeInBytes,
picture_cache_.size(), "PictureMBytes", "PictureCount", picture_cache_.size(), "PictureMBytes",
EstimatePictureCacheByteSize() / kMegaBytes); EstimatePictureCacheByteSize() / kMegaByteSizeInBytes);
#endif // !FLUTTER_RELEASE #endif // !FLUTTER_RELEASE
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject_Internal.h" #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject_Internal.h"
#include "flutter/common/constants.h"
#include "flutter/common/task_runners.h" #include "flutter/common/task_runners.h"
#include "flutter/fml/mapping.h" #include "flutter/fml/mapping.h"
#include "flutter/fml/message_loop.h" #include "flutter/fml/message_loop.h"
...@@ -151,6 +152,16 @@ static flutter::Settings DefaultSettingsForProcess(NSBundle* bundle = nil) { ...@@ -151,6 +152,16 @@ static flutter::Settings DefaultSettingsForProcess(NSBundle* bundle = nil) {
make_mapping_callback(kPlatformStrongDill, kPlatformStrongDillSize); make_mapping_callback(kPlatformStrongDill, kPlatformStrongDillSize);
#endif // FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG #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; return settings;
} }
......
...@@ -2,8 +2,11 @@ ...@@ -2,8 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#import <OCMock/OCMock.h>
#import <XCTest/XCTest.h> #import <XCTest/XCTest.h>
#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" #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject_Internal.h"
FLUTTER_ASSERT_ARC FLUTTER_ASSERT_ARC
...@@ -19,6 +22,13 @@ FLUTTER_ASSERT_ARC ...@@ -19,6 +22,13 @@ FLUTTER_ASSERT_ARC
- (void)tearDown { - (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 { - (void)testMainBundleSettingsAreCorrectlyParsed {
NSBundle* mainBundle = [NSBundle mainBundle]; NSBundle* mainBundle = [NSBundle mainBundle];
NSDictionary* appTransportSecurity = NSDictionary* appTransportSecurity =
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册