Reduce CanvasKit memory use on Safari#186327
Draft
via-guy wants to merge 2 commits into
Draft
Conversation
a74b4eb to
058c0e0
Compare
058c0e0 to
f81d6fd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reduces Safari's CanvasKit memory footprint for Flutter web apps while preserving platform-view composition.
Safari can retain a much higher physical footprint than Chrome for CanvasKit apps. In a production-style Flutter web flow with a Google Maps platform view, the baseline Safari WebContent footprint was
639.0M / 652.8Mafter 60 seconds idle, while Chrome stayed around48.8M / 52.5MJS heap. This PR applies Safari-specific CanvasKit defaults, caps Safari's Skia resource cache, tightens web platform-view cleanup, and fixes anHtmlElementViewcreate/dispose race.Validation from the same flow after the change:
bin/flutterweb SDK cache:373.0M / 451.8Mafter 60 seconds idle, with the map visible.383.87M / 443.63Mmean after 60 seconds idle, with the map visible in all runs.48.9M / 52.3Mafter 60 seconds idle, matching the baseline.Fixes #93404
No
flutter/testsmigration is needed; this changes Flutter web engine and framework behavior without a breaking API change.Release / cherry-pick information
Issue Link:
#93404
Impact Description:
Safari web apps using CanvasKit can use several hundred MB more memory than Chrome and may slow or crash. Apps using platform views, such as Google Maps, also need the Safari memory reduction to preserve underlay/overlay composition so the platform view remains visible.
Changelog Description:
[flutter/93404] When running CanvasKit Flutter web apps on Safari, reduce memory footprint with Safari-specific CanvasKit defaults while preserving platform-view composition.
Workaround:
Apps can manually set
canvasKitForceCpuOnly: trueandcanvasKitMaximumSurfaces: 2, but this PR makes Safari defaults safer without requiring each app to configure them.Risk:
Test Coverage:
Validation Steps:
dart format engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/renderer.dart engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/surface.dart engine/src/flutter/lib/web_ui/lib/src/engine/compositing/rasterizer.dart engine/src/flutter/lib/web_ui/lib/src/engine/compositing/render_canvas.dart engine/src/flutter/lib/web_ui/lib/src/engine/compositing/surface.dart engine/src/flutter/lib/web_ui/lib/src/engine/configuration.dart engine/src/flutter/lib/web_ui/lib/src/engine/platform_views/content_manager.dart engine/src/flutter/lib/web_ui/test/canvaskit/rasterizer_test.dart engine/src/flutter/lib/web_ui/test/canvaskit/renderer_test.dart engine/src/flutter/lib/web_ui/test/engine/compositing/render_canvas_test.dart engine/src/flutter/lib/web_ui/test/engine/configuration_test.dart engine/src/flutter/lib/web_ui/test/engine/platform_views/content_manager_test.dart packages/flutter/lib/src/widgets/_html_element_view_web.dart packages/flutter/test/widgets/html_element_view_test.dartfelt test --browser=chrome --renderer=canvaskit --suite=chrome-dart2js-canvaskit-engine --fail-earlyfelt test --browser=chrome --renderer=canvaskit --suite=chrome-dart2js-canvaskit-canvaskit --fail-earlyflutter test --platform chrome test/widgets/html_element_view_test.dartgit diff --checkPre-launch Checklist
///).This is a draft until the submitter has completed human review of the AI-assisted changes and signed the CLA.