Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit aa01e25

Browse files
authored
iOS: Eliminate needless profiler metrics ivar (#55957)
iOS profiling is implemented in ProfileMetricsIOS, which has a default constructor, no member fields, and no superclass. i.e. it's roughly zero cost to create and holds no state. There's therefore no reason to make it an ivar on FlutterEngine. Further, making it an ivar on FlutterEngine means that the profiling sampler lambda needs to capture self which, in the case where all other FlutterEngine references go out of scope during sampling, means that the last FlutterEngine reference exists on a profiling thread, and when the sampling lambda block completes, the engine is dealloc'ed. The engine *must* be deallocated on the platform (main in Apple terminology) thread because FlutterEngine holds a reference to a PlatformViewsController, which owns a WeakPtrFactory. WeakPtrFactory's dtor asserts that it executes on the thread on which it was created, in this case, the platform thread. Further, the engine holds direct and indirect references to other UIKit objects such as `UITextInput` in FlutterTextInputPlugin, which must be dealloc'ed on the main thread. Since there's no need for ProfileMetricsIOS to be tied to the engine, we now create it on the fly in the sampler. No test changes because no semantic changes. Uncovered by ARC migration. Issue: flutter/flutter#137801 Issue: flutter/flutter#156177 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent f0235af commit aa01e25

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

shell/platform/darwin/ios/framework/Source/FlutterEngine.mm

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ @implementation FlutterEngine {
125125

126126
std::shared_ptr<flutter::PlatformViewsController> _platformViewsController;
127127
flutter::IOSRenderingAPI _renderingApi;
128-
std::shared_ptr<flutter::ProfilerMetricsIOS> _profiler_metrics;
129128
std::shared_ptr<flutter::SamplingProfiler> _profiler;
130129

131130
// Channels
@@ -570,10 +569,13 @@ - (void)resetChannels {
570569

571570
- (void)startProfiler {
572571
FML_DCHECK(!_threadHost->name_prefix.empty());
573-
_profiler_metrics = std::make_shared<flutter::ProfilerMetricsIOS>();
574572
_profiler = std::make_shared<flutter::SamplingProfiler>(
575573
_threadHost->name_prefix.c_str(), _threadHost->profiler_thread->GetTaskRunner(),
576-
[self]() { return self->_profiler_metrics->GenerateSample(); }, kNumProfilerSamplesPerSec);
574+
[]() {
575+
flutter::ProfilerMetricsIOS profiler_metrics;
576+
return profiler_metrics.GenerateSample();
577+
},
578+
kNumProfilerSamplesPerSec);
577579
_profiler->Start();
578580
}
579581

@@ -1486,7 +1488,6 @@ - (FlutterEngine*)spawnWithEntrypoint:(/*nullable*/ NSString*)entrypoint
14861488

14871489
result->_threadHost = _threadHost;
14881490
result->_profiler = _profiler;
1489-
result->_profiler_metrics = _profiler_metrics;
14901491
result->_isGpuDisabled = _isGpuDisabled;
14911492
[result setUpShell:std::move(shell) withVMServicePublication:NO];
14921493
return [result autorelease];

0 commit comments

Comments
 (0)