Skip to content

Conversation

@knopp
Copy link
Member

@knopp knopp commented Sep 25, 2025

Replaces SetTimer/WM_TIMER with a threadpool timer, which doesn't suffer from 16ms granularity and changes the waking up mechanism to give the run loop chance to process input messages before processing flutter tasks.

If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.

Pre-launch Checklist

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

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.

@flutter-dashboard

This comment was marked as outdated.

@github-actions github-actions bot added engine flutter/engine related. See also e: labels. platform-windows Building on or for Windows specifically a: desktop Running on desktop labels Sep 25, 2025
@knopp knopp force-pushed the fix_win_events branch 2 times, most recently from 7297da4 to 31d3582 Compare September 25, 2025 14:38
Copy link
Contributor

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

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 replaces the legacy SetTimer/WM_TIMER mechanism with a modern threadpool timer to achieve higher resolution and prevent deadlocks in the event loop. The overall approach is sound, but I've identified a critical issue with the timer configuration that would cause it to fire periodically instead of as a one-shot timer. Additionally, there are a couple of missing null checks for the new timer handle that could lead to crashes if timer creation fails. I've provided suggestions to fix these issues and a minor one to improve code robustness by initializing member variables.

Comment on lines +46 to 60
CloseThreadpoolTimer(timer_);

if (window_handle_) {
Copy link
Contributor

Choose a reason for hiding this comment

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

high

To prevent a crash if timer_ is nullptr (for example, if its creation failed in the constructor), this block of timer cleanup code should be wrapped in a null check.

  if (timer_) {
    SetThreadpoolTimer(timer_, nullptr, 0, 0);
    WaitForThreadpoolTimerCallbacks(timer_, TRUE);
    CloseThreadpoolTimer(timer_);
  }

Copy link
Member Author

Choose a reason for hiding this comment

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

Don't think this makes much sense to do. Failing to create the timer would pretty much render the application useless and will likely crash way earlier when trying to arm the timer.

@knopp knopp changed the title [wip] [win32] Use high resolution timer and avoid event deadlock [win32] Use high resolution timer and avoid event deadlock Sep 26, 2025
@knopp knopp requested a review from loic-sharma September 26, 2025 11:23
@knopp knopp changed the title [win32] Use high resolution timer and avoid event deadlock [win32] Runloop should use high resolution timer and avoid deadlock Sep 26, 2025
@knopp knopp requested a review from mattkae September 26, 2025 13:23
Copy link
Contributor

@mattkae mattkae left a comment

Choose a reason for hiding this comment

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

Feels smooth to me! I have some suggestions, but I'll let Loic be the final call

Copy link
Member

@loic-sharma loic-sharma left a comment

Choose a reason for hiding this comment

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

Thanks for the fix! Great tests :)

@loic-sharma
Copy link
Member

Does this improve #97334 by any chance? (I'm traveling and can't check myself)

@knopp
Copy link
Member Author

knopp commented Sep 26, 2025

Does this improve #97334 by any chance? (I'm traveling and can't check myself)

I have no idea really. The vsync waiter on windows needs some work I think. We have the period right, but not the initial offset (last time I checked).

@knopp knopp enabled auto-merge October 1, 2025 16:31
@knopp knopp added this pull request to the merge queue Oct 1, 2025
Merged via the queue into flutter:master with commit 77a581a Oct 1, 2025
184 of 185 checks passed
@knopp knopp deleted the fix_win_events branch October 1, 2025 18:09
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 1, 2025
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Oct 1, 2025
…10160)

Manual roll requested by [email protected]

flutter/flutter@c9608e2...7811e89

2025-10-01 [email protected] Migrate to `WidgetStateTextStyle` (flutter/flutter#176330)
2025-10-01 [email protected] Migrate to `WidgetStateOutlinedBorder` (flutter/flutter#176270)
2025-10-01 [email protected] [win32] Runloop should use high resolution timer and avoid deadlock (flutter/flutter#176023)
2025-10-01 [email protected] Roll Packages from 287739d to 321a584 (3 revisions) (flutter/flutter#176357)
2025-10-01 [email protected] Add SwiftUI support for UIScene migration (flutter/flutter#176230)
2025-10-01 [email protected] Roll Skia from ecaff95f51aa to c44a36470d07 (4 revisions) (flutter/flutter#176336)
2025-10-01 [email protected] [native assets] Enable build hooks and code assets on stable (flutter/flutter#176285)
2025-10-01 [email protected] [native assets] Roll dependencies (flutter/flutter#176287)
2025-10-01 [email protected] Roll Dart SDK from 527333cfe4cf to 8ffec1435cf3 (1 revision) (flutter/flutter#176334)
2025-10-01 [email protected] Roll Skia from 6998b06397c5 to ecaff95f51aa (1 revision) (flutter/flutter#176333)
2025-10-01 [email protected] Update description in _LastFinderMixin to properly describe finding last (flutter/flutter#174232)
2025-10-01 [email protected] Roll Skia from b242cc09488d to 6998b06397c5 (2 revisions) (flutter/flutter#176331)
2025-10-01 [email protected] Roll Dart SDK from af31d2637b6b to 527333cfe4cf (17 revisions) (flutter/flutter#176325)
2025-10-01 [email protected] Stop using deprecated analyzer 7.x.y APIs. (flutter/flutter#176242)
2025-10-01 [email protected] Fix docs referencing deprecated radio properties (flutter/flutter#176244)
2025-09-30 [email protected] Roll Skia from bb3b6bd4be0d to b242cc09488d (22 revisions) (flutter/flutter#176320)
2025-09-30 [email protected] Roll Fuchsia Linux SDK from rcOl0yxJb4znJ903Y... to 1Ai6VL4vb_GdGnWhg... (flutter/flutter#176315)
2025-09-30 [email protected] Adds dart ui API for setting application level locale (flutter/flutter#175100)
2025-09-30 [email protected] replace `onPop` usage with `onPopWithResult` in `navigation_bar.2.dart ` (flutter/flutter#174841)
2025-09-30 [email protected] [ Widget Preview ] Forward Widget Inspector navigation events via DTD (flutter/flutter#176218)
2025-09-30 [email protected] Add verbose logs to module_uiscene_test_ios (flutter/flutter#176306)
2025-09-30 [email protected] Web semantics: Fix email field selection/cursor by using type="text" + inputmode="email" (flutter/flutter#175876)

If this roll has caused a breakage, revert this CL and stop the roller
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
@Eerey
Copy link

Eerey commented Oct 2, 2025

Will this fix this issue aswell?
#174904

okorohelijah pushed a commit to okorohelijah/flutter that referenced this pull request Oct 7, 2025
…lutter#176023)

Replaces `SetTimer`/`WM_TIMER` with a threadpool timer, which doesn't
suffer from 16ms granularity and changes the waking up mechanism to give
the run loop chance to process input messages before processing flutter
tasks.

- Fixes flutter#173843
- Fixes flutter#175135

*If you had to change anything in the [flutter/tests] repo, include a
link to the migration guide as per the [breaking change policy].*

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

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

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
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.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 12, 2025
reidbaker pushed a commit to AbdeMohlbi/flutter that referenced this pull request Dec 10, 2025
…lutter#176023)

Replaces `SetTimer`/`WM_TIMER` with a threadpool timer, which doesn't
suffer from 16ms granularity and changes the waking up mechanism to give
the run loop chance to process input messages before processing flutter
tasks.

- Fixes flutter#173843
- Fixes flutter#175135

*If you had to change anything in the [flutter/tests] repo, include a
link to the migration guide as per the [breaking change policy].*

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

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

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
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.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: desktop Running on desktop engine flutter/engine related. See also e: labels. platform-windows Building on or for Windows specifically

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Windows] app frame rate unstable since Flutter 3.35.0 [Windows] Windows tasks aren't processed if the Dart event loop is never drained

4 participants