Skip to content

Offload blocking work in ProcessTextPlugin to the background - #189823

Merged
auto-submit[bot] merged 1 commit into
flutter:masterfrom
xRossKoh:fix-process-text-plugin
Aug 12, 2026
Merged

auto-submit[bot] merged 1 commit into
flutter:masterfrom
xRossKoh:fix-process-text-plugin

Conversation

@xRossKoh

@xRossKoh xRossKoh commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

This PR offloads the method handlers of the ProcessTextPlugin to a background TaskQueue.

The offloading of the querying of text actions to a background thread moves the following transactions off the main thread:

  1. Binder transaction of querying the package manager for activities with process text intent
  2. Disk I/O transactions of resolving the text action labels from the APKs of the individual activities

The above transactions occurring on the main thread is an anti-pattern according to https://developer.android.com/topic/performance/anrs/find-unresponsive-thread#common-causes Attached below is a Perfetto trace validating that the querying of text actions now occurs on a background thread.

image

The processTextAction method handler is also moved to a background thread, with additional handling to ensure that the launching of the text action activity is delegated back to the main UI thread. Attached below is a Perfetto trace validating that the processing of a text action begins on a background thread but is later delegated back to the main thread to launch the activity.

image

Note that the above Perfetto traces have additional trace logging implemented to better visualize when the method handlers are called.

This PR also refactors ProcessTextChannel to use DartExecutor.getBinaryMessenger() instead of using DartExecutor as the BinaryMessenger object directly, so that the deprecated wrapper methods of BinaryMessenger in DartExecutor are no longer used.

// ------ START BinaryMessenger (Deprecated: use getBinaryMessenger() instead) -----
/** @deprecated Use {@link #getBinaryMessenger()} instead. */
@Deprecated
@UiThread
@Override
public TaskQueue makeBackgroundTaskQueue(TaskQueueOptions options) {
return binaryMessenger.makeBackgroundTaskQueue(options);
}
/** @deprecated Use {@link #getBinaryMessenger()} instead. */
@Deprecated
@Override
@UiThread
public void send(@NonNull String channel, @Nullable ByteBuffer message) {
binaryMessenger.send(channel, message);
}
/** @deprecated Use {@link #getBinaryMessenger()} instead. */
@Deprecated
@Override
@UiThread
public void send(
@NonNull String channel,
@Nullable ByteBuffer message,
@Nullable BinaryMessenger.BinaryReply callback) {
binaryMessenger.send(channel, message, callback);
}
/** @deprecated Use {@link #getBinaryMessenger()} instead. */
@Deprecated
@Override
@UiThread
public void setMessageHandler(
@NonNull String channel, @Nullable BinaryMessenger.BinaryMessageHandler handler) {
binaryMessenger.setMessageHandler(channel, handler);
}
/** @deprecated Use {@link #getBinaryMessenger()} instead. */
@Deprecated
@Override
@UiThread
public void setMessageHandler(
@NonNull String channel,
@Nullable BinaryMessenger.BinaryMessageHandler handler,
@Nullable TaskQueue taskQueue) {
binaryMessenger.setMessageHandler(channel, handler, taskQueue);
}
/** @deprecated Use {@link #getBinaryMessenger()} instead. */
@Deprecated
@Override
public void enableBufferingIncomingMessages() {
dartMessenger.enableBufferingIncomingMessages();
}
/** @deprecated Use {@link #getBinaryMessenger()} instead. */
@Deprecated
@Override
public void disableBufferingIncomingMessages() {
dartMessenger.disableBufferingIncomingMessages();
}
// ------ END BinaryMessenger -----

The unit tests for ProcessTextPlugin have also been refactored as such and the obsolete tags to suppress deprecated warnings have also been cleaned up.

Issue: #189176

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@github-actions github-actions Bot added a: text input Entering text in a text field or keyboard related problems platform-android Android applications specifically engine flutter/engine related. See also e: labels. team-android Owned by Android platform team labels Jul 22, 2026
@google-cla

google-cla Bot commented Jul 22, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@xRossKoh
xRossKoh force-pushed the fix-process-text-plugin branch 18 times, most recently from 7eb194b to b7a8ddb Compare July 23, 2026 08:00
@jiahaog jiahaog changed the title Optimize ProcessTextPlugin. Offload blocking work in ProcessTextPlugin to the background Jul 23, 2026
@xRossKoh
xRossKoh force-pushed the fix-process-text-plugin branch 2 times, most recently from 9ecf055 to 7d49049 Compare July 24, 2026 02:39
@xRossKoh
xRossKoh marked this pull request as ready for review July 24, 2026 02:47
@xRossKoh
xRossKoh requested a review from a team as a code owner July 24, 2026 02:47
@xRossKoh
xRossKoh removed the request for review from a team July 24, 2026 02:47
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Aug 4, 2026
@jiahaog jiahaog added the CICD Run CI/CD label Aug 4, 2026
@mboetger

mboetger commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

In #189176:

As for next steps, I intend to validate the proposed fix on my app internally.

Were you able to validate the fix?

mboetger
mboetger previously approved these changes Aug 4, 2026

@mboetger mboetger 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.

LGTM with a tiny nit.

@xRossKoh
xRossKoh force-pushed the fix-process-text-plugin branch from e6b4f3b to 9c0da0c Compare August 5, 2026 02:20
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Aug 5, 2026
@xRossKoh
xRossKoh force-pushed the fix-process-text-plugin branch from 9c0da0c to 7ffe6b7 Compare August 5, 2026 02:39
…skQueue

Offload ProcessTextPlugin label resolution to a background TaskQueue to prevent main-thread ANRs during Android PackageManager IPC queries.
@xRossKoh
xRossKoh force-pushed the fix-process-text-plugin branch from 7ffe6b7 to b8015ae Compare August 5, 2026 02:45
@jiahaog jiahaog added the CICD Run CI/CD label Aug 5, 2026
@xRossKoh
xRossKoh requested a review from mboetger August 11, 2026 05:12
@mboetger

Copy link
Copy Markdown
Contributor

In #189176:

As for next steps, I intend to validate the proposed fix on my app internally.

Were you able to validate the fix?

Spoke to developer offline. No, they were not able to validate the fix or repro the issue.

@mboetger mboetger added CICD Run CI/CD and removed CICD Run CI/CD labels Aug 11, 2026

@mboetger mboetger 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.

Optimization seems reasonable to me even if it may not fix the associated ANR.

@gmackall gmackall added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 11, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Aug 11, 2026
Merged via the queue into flutter:master with commit 3ec72ae Aug 12, 2026
37 of 38 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 12, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Aug 13, 2026
…#12453)

Manual roll Flutter from 27b098811f3b to c2437523d308 (179 revisions)

Manual roll requested by [email protected]

flutter/flutter@27b0988...c243752

2026-08-12 [email protected] Enable Gradle CI cache on all test targets that require android_sdk (flutter/flutter#190723)
2026-08-12 [email protected] [analysis] Reland "Added initial implementation of the flutter_analyzer_plugin (#175679)" (flutter/flutter#191022)
2026-08-12 [email protected] Switch testing to gradle bin distribution type instead of all (flutter/flutter#190738)
2026-08-12 [email protected] Convert Mockito instances in Kotlin to Mockk (flutter/flutter#189884)
2026-08-12 [email protected] Report individual test results to LUCI ResultDB (flutter/flutter#190254)
2026-08-12 [email protected] Toggleable reaction duration respects overrides (flutter/flutter#190857)
2026-08-12 [email protected] Roll Skia from e00dbd7448c4 to fee7272f5bc2 (1 revision) (flutter/flutter#191007)
2026-08-12 [email protected] Started caching text shadows by content. (flutter/flutter#190681)
2026-08-12 [email protected] Adds agent skill for spawning led tasks. (flutter/flutter#190937)
2026-08-12 [email protected] Roll Packages from aaaf246 to 94485f1 (8 revisions) (flutter/flutter#191008)
2026-08-12 [email protected] flutter_tools: validate plugin identifiers before generating registrant code (flutter/flutter#190462)
2026-08-12 [email protected] Roll Skia from 112f36148949 to e00dbd7448c4 (3 revisions) (flutter/flutter#190993)
2026-08-12 [email protected] Roll Skia from 7d366c802307 to 112f36148949 (3 revisions) (flutter/flutter#190983)
2026-08-12 [email protected] remove bringup for flavors test (flutter/flutter#190940)
2026-08-12 [email protected] Roll Skia from 1f10a20bdd61 to 7d366c802307 (2 revisions) (flutter/flutter#190980)
2026-08-12 [email protected] Remove `--no-sim-use-hardfp` flag (flutter/flutter#190790)
2026-08-12 [email protected] Roll pub packages (flutter/flutter#190977)
2026-08-12 [email protected] Roll Skia from 339bedab6766 to 1f10a20bdd61 (1 revision) (flutter/flutter#190975)
2026-08-12 [email protected] RawTooltip respects AnimationStyle updates and reverseCurve (flutter/flutter#190889)
2026-08-12 [email protected] ci: Support --target_arch option in prepare_package.dart (flutter/flutter#190960)
2026-08-12 [email protected] Roll Fuchsia Linux SDK from SFq4FVodIOQAS26Lr... to -uHuSGv3wt7QAlDwa... (flutter/flutter#190973)
2026-08-12 [email protected] Removes building of ci/android_debug_x86 as nobody should be consuming it. (flutter/flutter#190951)
2026-08-12 [email protected] Adds error about wimp_heavy not being implemented. (flutter/flutter#189945)
2026-08-11 [email protected] Add clang, cmake, and ninja deps to Linux windowing_test (flutter/flutter#190119)
2026-08-11 [email protected] [AGP 9.1.0 Migration #1] Add Android Gradle Plugin Public API migration documentation (flutter/flutter#190842)
2026-08-11 [email protected] [flutter_tools] Fix deadlock in debug adapters when process exits early (flutter/flutter#190931)
2026-08-11 [email protected] [tool] Define modular dependency injection containers and bootstrapper (flutter/flutter#190724)
2026-08-11 [email protected] [web] Unify MaskFilter and ColorFilter primitives across CanvasKit and Skwasm (flutter/flutter#190314)
2026-08-11 [email protected] Roll pub packages (flutter/flutter#190958)
2026-08-11 [email protected] [Impeller] Move image upload scheduling waits to GPU disable (flutter/flutter#190445)
2026-08-11 [email protected] Started generating the windows platform for macrobenchmarks (flutter/flutter#190932)
2026-08-11 [email protected] [web] Unify ui.Vertices (flutter/flutter#190563)
2026-08-11 [email protected] Fix accessibility_inspector service extensions map mutability (flutter/flutter#190888)
2026-08-11 [email protected] Add batch3 a11y_assessment for vpat (flutter/flutter#189042)
2026-08-11 [email protected] Remove Xcode environment when building swift tools in Xcode pre-action (flutter/flutter#190848)
2026-08-11 [email protected] [tool] Add missing play element in web test index.html to fix warning (flutter/flutter#190675)
2026-08-11 [email protected] Offload blocking work in ProcessTextPlugin to the background (flutter/flutter#189823)
2026-08-11 [email protected] [flutter_tools] Replace usages of package:dds/dap.dart with package:dap_adapters/dap_adapters.dart (flutter/flutter#190667)
2026-08-11 [email protected] Always update swift package dependencies (flutter/flutter#190886)
2026-08-11 [email protected] [flutter_tools] Add --preset option to flutter test (flutter/flutter#190878)
2026-08-11 [email protected] Include the examples cross imports checker in the analzyer. (flutter/flutter#190674)
2026-08-11 [email protected] [devicelab] Remove orphaned screenshot test files (flutter/flutter#190879)
2026-08-11 [email protected] Remove the bringup flag from the linux_arm_host_desktop_engine builder (flutter/flutter#190935)
2026-08-11 [email protected] Reduce web_skwasm_tests subshards from 8 to 2 (flutter/flutter#190728)
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: text input Entering text in a text field or keyboard related problems CICD Run CI/CD engine flutter/engine related. See also e: labels. platform-android Android applications specifically team-android Owned by Android platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants