Skip to content

Move the task runners out of Flutter Engine - #196267

Merged
auto-submit[bot] merged 9 commits into
flutter:masterfrom
LouiseHsu:p1-1c-task-runners
Nov 16, 2026
Merged

auto-submit[bot] merged 9 commits into
flutter:masterfrom
LouiseHsu:p1-1c-task-runners

Conversation

@LouiseHsu

@LouiseHsu LouiseHsu commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Moves the Task-runner wrappers + the three accessors out of FlutterEngine and into FlutterShell.

part of #112232
1.1c of flutter/rfc#27

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant in-code documentation (doc comments with ///).
  • If this PR introduces a new feature or capability, I created and linked a website documentation issue or PR in [flutter/website] (or verified none is needed).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • I followed the [breaking change policy] and added [Data Driven Fixes] where supported.
  • All existing and new tests are passing.

@github-actions github-actions Bot added platform-ios iOS applications specifically engine flutter/engine related. See also e: labels. team-ios Owned by iOS platform team labels Nov 10, 2026
@LouiseHsu LouiseHsu added the CICD Run CI/CD label Nov 10, 2026
@LouiseHsu
LouiseHsu requested a review from cbracken November 12, 2026 23:39
@LouiseHsu
LouiseHsu marked this pull request as ready for review November 12, 2026 23:39
@LouiseHsu
LouiseHsu requested a review from a team as a code owner November 12, 2026 23:39

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors task runner management by centralizing it within the FlutterShell backend, introducing adoptTaskRunners and resetTaskRunners methods, and exposing task runner properties in the FlutterShell interface. New tests were added to verify these changes. The review feedback suggests improving thread safety by declaring task runner properties as atomic, utilizing synthesized setters, and adding null checks to the test helper function to prevent potential crashes.

Comment on lines +25 to +35
@property(nonatomic, readonly, nullable) FlutterFMLTaskRunner* platformTaskRunner;

/// The task runner for the UI thread, where framework code runs, or nil before task runners are
/// adopted and after `resetTaskRunners`.
///
/// The platform and UI threads are always merged on iOS, so this is the platform task runner.
@property(nonatomic, readonly, nullable) FlutterFMLTaskRunner* uiTaskRunner;

/// The task runner for the raster thread, where GPU rasterisation commands are issued, or nil
/// before task runners are adopted and after `resetTaskRunners`.
@property(nonatomic, readonly, nullable) FlutterFMLTaskRunner* rasterTaskRunner;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since these task runner properties can be accessed from multiple threads (e.g., to post tasks to the platform or raster threads) while being modified on the platform thread during startup/teardown, they should be declared as atomic to prevent race conditions under ARC.

@property(atomic, readonly, nullable) FlutterFMLTaskRunner* platformTaskRunner;

/// The task runner for the UI thread, where framework code runs, or nil before task runners are
/// adopted and after `resetTaskRunners`.
///
/// The platform and UI threads are always merged on iOS, so this is the platform task runner.
@property(atomic, readonly, nullable) FlutterFMLTaskRunner* uiTaskRunner;

/// The task runner for the raster thread, where GPU rasterisation commands are issued, or nil
/// before task runners are adopted and after `resetTaskRunners`.
@property(atomic, readonly, nullable) FlutterFMLTaskRunner* rasterTaskRunner;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary.

These are all managed from the platform thread. The only place we reference these off thread is from the raster thread on startup (first frame callback). And teardown, which already waits on all the raster thread work. All the synchronisation around this was already done in work by jsimmons and myself a couple months ago.

Comment on lines +21 to +22
/// Creates the platform and raster task runner wrappers from `taskRunners`.
- (void)adoptTaskRunners:(const flutter::TaskRunners&)taskRunners;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Redeclare the properties as readwrite in the internal class extension to allow thread-safe atomic setters to be synthesized and used within FlutterShell.

@property(atomic, readwrite, nullable) FlutterFMLTaskRunner* platformTaskRunner;
@property(atomic, readwrite, nullable) FlutterFMLTaskRunner* rasterTaskRunner;

/// Creates the platform and raster task runner wrappers from `taskRunners`.
- (void)adoptTaskRunners:(const flutter::TaskRunners&)taskRunners;

Comment on lines 110 to 113

FlutterFMLTaskRunner* _platformTaskRunnerWrapper;
FlutterFMLTaskRunner* _rasterTaskRunnerWrapper;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Remove the manual instance variables _platformTaskRunnerWrapper and _rasterTaskRunnerWrapper to let the compiler automatically synthesize the backing ivars for the atomic properties.

}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay this is fair. The public header declares readonly properties so the compiler should synthenise these just fine. You can drop the two manual ivar declarations.

@LouiseHsu LouiseHsu changed the title P1 1c move the task runners Move the task runners out of Flutter Engine Nov 12, 2026

@cbracken cbracken left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM stamp from a Japanese personal seal

LGTM! Looks awesome. Just a few nits!

Comment on lines +25 to +35
@property(nonatomic, readonly, nullable) FlutterFMLTaskRunner* platformTaskRunner;

/// The task runner for the UI thread, where framework code runs, or nil before task runners are
/// adopted and after `resetTaskRunners`.
///
/// The platform and UI threads are always merged on iOS, so this is the platform task runner.
@property(nonatomic, readonly, nullable) FlutterFMLTaskRunner* uiTaskRunner;

/// The task runner for the raster thread, where GPU rasterisation commands are issued, or nil
/// before task runners are adopted and after `resetTaskRunners`.
@property(nonatomic, readonly, nullable) FlutterFMLTaskRunner* rasterTaskRunner;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary.

These are all managed from the platform thread. The only place we reference these off thread is from the raster thread on startup (first frame callback). And teardown, which already waits on all the raster thread work. All the synchronisation around this was already done in work by jsimmons and myself a couple months ago.

Comment on lines 110 to 113

FlutterFMLTaskRunner* _platformTaskRunnerWrapper;
FlutterFMLTaskRunner* _rasterTaskRunnerWrapper;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay this is fair. The public header declares readonly properties so the compiler should synthenise these just fine. You can drop the two manual ivar declarations.

return _threadHost.get();
}

- (void)adoptTaskRunners:(const flutter::TaskRunners&)taskRunners {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a dcheck here:

FML_DCHECK(!_platformTaskRunner && !_rasterTaskRunner);

This is similar to what we do with _threadHost in inheritThreadHostFromShell:.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

/// The shell using these threads must be destroyed before calling this method.
- (void)destroyThreadHost;

/// Releases the task runner wrappers.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a reference to where these are adopted since that happens in the internal header.

Suggested change
/// Releases the task runner wrappers.
/// Releases the task runner wrappers.
///
/// @see `adoptTaskRunners:` in FlutterShell_Internal.h.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doneeee


// The platform and UI threads are always merged on iOS.
XCTAssertEqual(shell.uiTaskRunner, shell.platformTaskRunner);
XCTAssertNotEqual(shell.rasterTaskRunner, shell.platformTaskRunner);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit separate from checking the platform and UI threads are merged. It's checking the raster thread isn't also merged, which is fine and should be definitely be the case, but you might want to document this line with a separate comment.

Suggested change
XCTAssertNotEqual(shell.rasterTaskRunner, shell.platformTaskRunner);
// The platform and raster threads are not merged on iOS.
XCTAssertNotEqual(shell.rasterTaskRunner, shell.platformTaskRunner);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

donesies

cbracken
cbracken previously approved these changes Nov 13, 2026
@LouiseHsu
LouiseHsu requested a review from cbracken November 14, 2026 00:51

@cbracken cbracken left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-lgtm!

@LouiseHsu LouiseHsu added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 16, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Nov 16, 2026
Merged via the queue into flutter:master with commit c12369e Nov 16, 2026
23 of 24 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 16, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Nov 17, 2026
flutter/flutter@d8bd864...2f09f96

2026-11-17 [email protected] Analyze every flutter create template, and fix the package_ffi lint (flutter/flutter#196165)
2026-11-17 [email protected] Roll Dart SDK from 50debf3c9757 to 26e38955d9d4 (3 revisions) (flutter/flutter#196772)
2026-11-17 [email protected] Manual roll ICU from b09986242cfb to d3c612f44146 (1 revision) (flutter/flutter#196713)
2026-11-17 [email protected] Roll Skia from 4f6b3a8d8565 to 503a380ebecc (19 revisions) (flutter/flutter#196768)
2026-11-17 [email protected] iOS: Don't mock UIView animations in keyboard spring animation test (flutter/flutter#196755)
2026-11-17 [email protected] [flutter_tools] Preserve index.html across --web-content-hash transitions (flutter/flutter#196491)
2026-11-17 [email protected] Fix TextStyle background color fade-out when lerping to null (flutter/flutter#196153)
2026-11-17 [email protected] Update desktop engine TESTOWNERS (flutter/flutter#196732)
2026-11-17 [email protected] [flutter_tools] Do not copy app-only build type properties onto library plugins (flutter/flutter#196692)
2026-11-17 [email protected] [flutter_tools] Remove service and runner ambient context getters (flutter/flutter#196571)
2026-11-17 [email protected] Bump customer tests (flutter/flutter#196740)
2026-11-17 [email protected] Take customer_testing_flame out of bringup (flutter/flutter#196570)
2026-11-17 [email protected] [devicelab] Read AssetManifest.bin from the APK in flavors_test (flutter/flutter#196736)
2026-11-17 [email protected] [flutter_tools] Fix flaky tool_tests_general by moving spawnUri tests to integration shard (flutter/flutter#195999)
2026-11-17 [email protected] Roll Dart SDK from 3e069c6fdbde to 50debf3c9757 (2 revisions) (flutter/flutter#196706)
2026-11-16 [email protected] [web] Record build finish synchronously in renderScene and fix dropped frame timings (flutter/flutter#195947)
2026-11-16 [email protected] Do not reveal obscured character when input is rejected by inputFormatters (flutter/flutter#195022)
2026-11-16 [email protected] Cla draft follow up: add waiting for response (flutter/flutter#196686)
2026-11-16 [email protected] Roll pub packages (flutter/flutter#196684)
2026-11-16 [email protected] Roll Packages from 015df97 to 4c6a7d3 (8 revisions) (flutter/flutter#196681)
2026-11-16 [email protected] Skip Vulkan impeller_unittests on macOS (flutter/flutter#196282)
2026-11-16 [email protected] Move the task runners out of Flutter Engine (flutter/flutter#196267)
2026-11-16 [email protected] [FGP] Add Flutter assets after AGP's asset merge so dotfiles are pack… (flutter/flutter#196465)
2026-11-16 [email protected] iOS: Add Obj-C model for platform view composition params (flutter/flutter#196498)
2026-11-16 [email protected] [Windows] Normalize Shift key messages with a non-standard scan code (flutter/flutter#193675)
2026-11-16 [email protected] Roll Skia from 118eaff3deb4 to 4f6b3a8d8565 (3 revisions) (flutter/flutter#196672)
2026-11-16 [email protected] Roll Dart SDK from c91e8b6674e2 to 3e069c6fdbde (4 revisions) (flutter/flutter#196669)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD engine flutter/engine related. See also e: labels. platform-ios iOS applications specifically team-ios Owned by iOS platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants