Skip to content

Reduce CanvasKit memory use on Safari#186327

Draft
via-guy wants to merge 2 commits into
flutter:masterfrom
via-guy:fix/safari-memory-footprint
Draft

Reduce CanvasKit memory use on Safari#186327
via-guy wants to merge 2 commits into
flutter:masterfrom
via-guy:fix/safari-memory-footprint

Conversation

@via-guy
Copy link
Copy Markdown

@via-guy via-guy commented May 10, 2026

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.8M after 60 seconds idle, while Chrome stayed around 48.8M / 52.5M JS heap. This PR applies Safari-specific CanvasKit defaults, caps Safari's Skia resource cache, tightens web platform-view cleanup, and fixes an HtmlElementView create/dispose race.

Validation from the same flow after the change:

  • Final Safari run through the normal bin/flutter web SDK cache: 373.0M / 451.8M after 60 seconds idle, with the map visible.
  • Three cached Safari repeats: 383.87M / 443.63M mean after 60 seconds idle, with the map visible in all runs.
  • Chrome guard through the normal SDK cache: 48.9M / 52.3M after 60 seconds idle, matching the baseline.

Fixes #93404

No flutter/tests migration 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: true and canvasKitMaximumSurfaces: 2, but this PR makes Safari defaults safer without requiring each app to configure them.

Risk:

  • Low
  • Medium
  • High

Test Coverage:

  • Yes
  • No

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.dart
  • felt test --browser=chrome --renderer=canvaskit --suite=chrome-dart2js-canvaskit-engine --fail-early
  • felt test --browser=chrome --renderer=canvaskit --suite=chrome-dart2js-canvaskit-canvaskit --fail-early
  • flutter test --platform chrome test/widgets/html_element_view_test.dart
  • git diff --check
  • Manual Safari memory profile of the Rider web flow: home, trip options, and 60 seconds idle, including platform-view visibility checks.
  • Chrome memory profile of the same flow as a regression guard.

Pre-launch Checklist

This is a draft until the submitter has completed human review of the AI-assisted changes and signed the CLA.

@github-actions github-actions Bot added framework flutter/packages/flutter repository. See also f: labels. engine flutter/engine related. See also e: labels. platform-web Web applications specifically labels May 10, 2026
@via-guy via-guy force-pushed the fix/safari-memory-footprint branch from a74b4eb to 058c0e0 Compare May 11, 2026 08:12
@via-guy via-guy force-pushed the fix/safari-memory-footprint branch from 058c0e0 to f81d6fd Compare May 11, 2026 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engine flutter/engine related. See also e: labels. framework flutter/packages/flutter repository. See also f: labels. platform-web Web applications specifically

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Safari high memory usage

1 participant