Skip to content

[web] Record build finish synchronously in renderScene and fix dropped frame timings - #195947

Merged
auto-submit[bot] merged 8 commits into
flutter:masterfrom
harryterkelsen:flutter-flutter-193696-web-skwasmrenderer
Nov 17, 2026
Merged

auto-submit[bot] merged 8 commits into
flutter:masterfrom
harryterkelsen:flutter-flutter-193696-web-skwasmrenderer

Conversation

@harryterkelsen

@harryterkelsen harryterkelsen commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

In Flutter Web, multi-threaded WebAssembly backends (skwasm and wimp) queue incoming scenes in Renderer.renderScene when worker rasterization spans more than one frame interval.

Previously, recorder?.recordBuildFinish() was deferred downstream to Frame.raster and ViewRasterizer.draw. For queued scenes, the duration spent sitting in renderQueue.next waiting for an in-flight raster to complete was erroneously included in buildDuration, inflating build time telemetry and blaming rasterizer backpressure on UI thread build performance.

This change records buildFinish synchronously in Renderer.renderScene at the boundary where the framework hands the scene to the engine, removes downstream duplicate calls to prevent double-record assertion failures, moves recordRasterStart() to the start of ViewRasterizer.draw so the engine's preroll, measure, composition optimization, and paint passes are counted as raster time, and ensures overwritten queued frames complete their futures while discarding timings cleanly.

Part of #193696

Behavioral Changes

  • Before: For scenes queued behind in-flight rasterization, buildDuration reported in FrameTiming included the waiting time spent in renderQueue.next (e.g. ~101ms instead of <50ms when in-flight raster took 100ms).
  • After: buildDuration strictly measures the UI build phase up to Renderer.renderScene submission, cleanly separating build time from engine raster queue latency.
  • Before: rasterStart was recorded inside each rasterizer's rasterize(), after the engine's preroll, measure, composition optimization, and paint passes (which previously counted toward build time).
  • After: rasterStart is recorded in ViewRasterizer.draw immediately before Frame.raster, so that engine work and prepareToDraw count toward rasterDuration, matching native where the raster thread performs preroll and paint.
  • Overwritten queued frames that are displaced before presentation complete their completion futures cleanly and discard their FrameTimingRecorder without submitting unpresented timings to onReportTimings.

Where to focus

  • Key Architectural Decisions:
    • Moving recordBuildFinish() to the framework-to-engine handoff boundary in Renderer.renderScene aligns with native Animator::EndFrame semantics and restores pre-unification behavior.
    • Recording recordRasterStart() once in ViewRasterizer.draw (and removing it from OffscreenCanvasRasterizer.rasterize and MultiSurfaceRasterizer.rasterize) keeps engine-side layer tree work inside rasterDuration instead of leaving it unaccounted between buildFinish and rasterStart.
    • Removing downstream recordBuildFinish() invocations from Frame.raster and ViewRasterizer.draw ensures FrameTimingRecorder.recordBuildFinish() is called exactly once per submitted frame and never asserts.
  • Non-Obvious Logic:
    • When renderQueue.next is replaced by a newer frame under raster backpressure, the dropped request's completer completes, but its FrameTimingRecorder is discarded without calling submitTimings() to preserve the historical Flutter Web contract that only presented frames report timings.
  • Primary Review Files:
    • engine/src/flutter/lib/web_ui/lib/src/engine/renderer.dart: Synchronous build finish recording and dropped frame handling.
    • engine/src/flutter/lib/web_ui/lib/src/engine/layer/layer_tree.dart: Removal of duplicate downstream call in Frame.raster.
    • engine/src/flutter/lib/web_ui/lib/src/engine/compositing/rasterizer.dart: Removal of duplicate build finish call and new raster start placement in ViewRasterizer.draw.
    • engine/src/flutter/lib/web_ui/lib/src/engine/compositing/offscreen_canvas_rasterizer.dart, multi_surface_rasterizer.dart: Removal of per-rasterizer raster start calls.
    • engine/src/flutter/lib/web_ui/test/ui/render_queue_test.dart: Complete unit and stress tests.

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.

Move recordRasterStart() from the per-rasterizer rasterize() implementations
to ViewRasterizer.draw, immediately before the compositor frame runs the
engine's preroll, measure, composition optimization, and paint passes. This
keeps that engine work in the reported raster duration now that build finish
is recorded when the scene is submitted to the renderer.
@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. platform-web Web applications specifically team-web Owned by Web platform team labels Nov 4, 2026
@harryterkelsen
harryterkelsen marked this pull request as ready for review November 11, 2026 00:20
@harryterkelsen harryterkelsen added the CICD Run CI/CD label Nov 11, 2026

@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 adjusts the timing of frame recording phases in the web engine. It moves the recording of build completion (recordBuildFinish) to immediately when a scene is received in Renderer.renderScene before queuing, and consolidates the start of rasterization recording (recordRasterStart) in ViewRasterizer.draw before the frame is rasterized. A new test suite render_queue_test.dart is added to verify these timing behaviors. There are no review comments, and I have no feedback to provide.

mdebbar
mdebbar previously approved these changes Nov 13, 2026
@harryterkelsen harryterkelsen 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 c3469b1 Nov 17, 2026
23 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 17, 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-web Web applications specifically team-web Owned by Web platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants