Skip to content

[Impeller] Reuse render targets on text shadow cache misses - #194769

Merged
auto-submit[bot] merged 7 commits into
flutter:masterfrom
M0n7y5:pr-a-shadow-cache
Nov 19, 2026
Merged

auto-submit[bot] merged 7 commits into
flutter:masterfrom
M0n7y5:pr-a-shadow-cache

Conversation

@M0n7y5

@M0n7y5 M0n7y5 commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

TextShadowCache::Lookup runs the Gaussian blur with RenderTargetCache::DisableCache(). Every miss allocates a fresh MSAA color + depth-stencil pair and two blur textures per shadow, then frees them. Entries are also evicted after one unused frame, so text whose glyphs change (typing dots, counters) misses on every change.

This PR:

  • Runs the blur with the cache enabled and removes only the output texture from reuse, via new RenderTargetAllocator::RemoveFromCache.
  • Keeps entries for up to 240 unused frames under an 8 MiB LRU byte budget. Entries used this frame are exempt.

Measured on a moto g54 5G (PowerVR BXM-8-256, Impeller OpenGLES); output is pixel-identical. A Redmi Note 12 Pro 5G (Mali-G68) shows the same per-frame churn on 3.47.7 and the same fix (raster p50 5.35 to 1.94 ms on the repro).

scene before after
cycling two-shadow label allocates in 26% of frames (6 TexImage2D, 9 render passes at p90) 0.1% of frames, 1 pass
real app, same scene 406 allocating frames, release raster p50 5.94 ms 4 frames, 5.16 ms

The real app baseline is Flutter 3.47.7, so part of that raster gain comes from master.

Tests (passing on OpenGLES and Vulkan): TextShadowCacheMissReusesBlurRenderTargets, TextShadowCacheHitsCyclingTextOfDifferentSizes, TextShadowCacheEntrySurvivesKeepAliveFrames, TextShadowCacheEvictsLeastRecentlyUsedOverBudget, TextShadowCacheKeepsEntriesUsedThisFrameOverBudget, RenderTargetCacheTest.RemovedTextureIsNotReused.

Caveats:

Fixes #194773
Related: #190681 (content fingerprint key, fixes unchanged text; this PR handles changing text), #194307, #184496.

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.

@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 introduces a byte budget and a keep-alive frame mechanism to the TextShadowCache in Impeller, allowing cached text shadows to survive across multiple frames and evicting the least recently used entries when over budget. It also adds a mechanism to remove textures from the RenderTargetCache to prevent them from being reused while still referenced by the shadow cache, along with corresponding unit tests. The review feedback highlights a potential null pointer dereference if snapshot->texture is null, suggesting a defensive check before dereferencing it.

@github-actions github-actions Bot added a: text input Entering text in a text field or keyboard related problems engine flutter/engine related. See also e: labels. e: impeller Impeller rendering backend issues and features requests labels Oct 19, 2026
TextShadowCache::Lookup ran the whole Gaussian blur with the
RenderTargetCache disabled, so every miss allocated a new MSAA snapshot
target, its depth-stencil and both blur targets, and freed them again.
Only the blur output has to outlive the frame.

Removing just that texture from the RenderTargetCache, with the new
RenderTargetAllocator::RemoveFromCache, keeps it from being handed out
again while the intermediates stay cached for later misses of the same
size. RenderToSnapshot resolves the filter result to that one texture;
for kNormal blurs it is a passthrough, so no copy is added.

Shadow entries were also evicted after the first render that did not
draw them, so text cycling through a few states (typing dots) missed
on every state change. Keep entries for up to 240 unused frames (2 s at
120 Hz) and bound the cache with an 8 MiB byte budget that evicts the
least recently used entries first, never ones drawn in the current
frame. A typical shadow texture is under 100 KB.
@M0n7y5
M0n7y5 force-pushed the pr-a-shadow-cache branch from 3bf4937 to c7e1191 Compare October 19, 2026 17:52
@gaaclarke gaaclarke added the CICD Run CI/CD label Oct 20, 2026
@gaaclarke
gaaclarke requested a review from flar October 20, 2026 20:37
@gaaclarke

Copy link
Copy Markdown
Member

@flar can you please give this a look when you have a chance

@flar flar 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 defensive nit.

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Oct 29, 2026
@flar flar added the CICD Run CI/CD label Oct 29, 2026
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Oct 30, 2026
@gaaclarke
gaaclarke requested a review from flar October 30, 2026 21:47
@gaaclarke

Copy link
Copy Markdown
Member

@M0n7y5 friendly reminder to hit "rerequest review" when you want someone to review it again.

@M0n7y5

M0n7y5 commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

@flar Any update on this?

@flar flar 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

@flar flar added the CICD Run CI/CD label Nov 14, 2026
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 14, 2026
@M0n7y5
M0n7y5 requested a review from flar November 15, 2026 12:27
@flar flar added the CICD Run CI/CD label Nov 17, 2026
@flar

flar commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

That's odd, a "merge branch master" shouldn't have removed the CICD label. I've merged it again and added CICD and my approval...

flar
flar previously approved these changes Nov 17, 2026

@flar flar 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 per previous review.

@gaaclarke
gaaclarke self-requested a review November 17, 2026 16:59

@gaaclarke gaaclarke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looking good, just some minor cleanup.

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 17, 2026
@M0n7y5
M0n7y5 requested a review from gaaclarke November 17, 2026 19:47
@gaaclarke gaaclarke added the CICD Run CI/CD label Nov 17, 2026

@gaaclarke gaaclarke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@gaaclarke
gaaclarke requested a review from flar November 17, 2026 21:09

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

I don't think that's a legal way to use iterators.

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

iterator usage appears to be valid for flat_hash_map.

@M0n7y5

M0n7y5 commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

So is that all? Do you guys need anything else changed?

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 18, 2026
@gaaclarke gaaclarke added CICD Run CI/CD autosubmit Merge PR when tree becomes green via auto submit App labels Nov 18, 2026
@gaaclarke

Copy link
Copy Markdown
Member

So is that all? Do you guys need anything else changed?

Should be fine as long as it passes CI. Feel free to share a celebratory emoji 🥳 👍 🥇

@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 19, 2026
@auto-submit

auto-submit Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

auto label is removed for flutter/flutter/194769, Failed to enqueue flutter/flutter/194769 with HTTP 400: Pull request Required status check "Check Code Freeze" is expected..

@gaaclarke gaaclarke added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 19, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Nov 19, 2026
Merged via the queue into flutter:master with commit f586770 Nov 19, 2026
24 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 19, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Nov 20, 2026
Roll Flutter from e8cc6f3451b7 to b34b017b48ad (36 revisions)

flutter/flutter@e8cc6f3...b34b017

2026-11-20 [email protected] Fix OverflowBox dry layout when deferToChild overrides the constraints (flutter/flutter#196839)
2026-11-20 [email protected] Roll Dart SDK from f118f476ebce to 3b5f45d812f8 (1 revision) (flutter/flutter#197048)
2026-11-20 [email protected] [macOS] Register plugins in multiple_windows example (flutter/flutter#196068)
2026-11-20 [email protected] Roll Skia from 87027a9d4659 to a1edf5c2ea5c (1 revision) (flutter/flutter#197045)
2026-11-20 [email protected] Add highp directives to UberSDF to prevent overflow (flutter/flutter#196997)
2026-11-20 [email protected] [Impeller] Cap the Vulkan command pool recycler cache (flutter/flutter#194793)
2026-11-20 [email protected] Roll Skia from 12610b69511d to 87027a9d4659 (4 revisions) (flutter/flutter#197037)
2026-11-20 [email protected] [macOS] Unregister nil binary message handlers (flutter/flutter#193672)
2026-11-20 [email protected] Roll Dart SDK from b803c3ec01de to f118f476ebce (2 revisions) (flutter/flutter#197034)
2026-11-20 [email protected] Roll Skia from 2f1436ba8e64 to 12610b69511d (3 revisions) (flutter/flutter#197030)
2026-11-20 [email protected] [Android] Do not use the HCPP external view embedder from its platform tasks (flutter/flutter#196490)
2026-11-20 [email protected] Roll Dart SDK from 849e17ad3ae6 to b803c3ec01de (1 revision) (flutter/flutter#197012)
2026-11-20 [email protected] [iOS a11y] Synchronize hit-test children when replacing semantics objects (flutter/flutter#196439)
2026-11-20 [email protected] Sync CHANGELOG.md from stable (flutter/flutter#197019)
2026-11-19 [email protected] [flutter_tools] Reland "Extract Windows archives using native tar" (flutter/flutter#193515)
2026-11-19 [email protected] [Reland][flutter_tools] Migrate lib/runner.dart off runInContext and overrides (flutter/flutter#196931)
2026-11-19 [email protected] Include assigned issues in Android incoming triage link (flutter/flutter#197008)
2026-11-19 [email protected] [Flutter GPU] Record on the UI thread, encode and submit on the raster thread (flutter/flutter#194882)
2026-11-19 [email protected] Add Pixel 7 Pro Impeller benchmarks without fixed-performance mode (flutter/flutter#197010)
2026-11-19 [email protected] Reduce time of uiscene_plugin_lifecycle_test_ios (flutter/flutter#196363)
2026-11-19 [email protected] [native assets] Respect Apple deployment targets (flutter/flutter#194146)
2026-11-19 [email protected] iOS: Represent platform view frames as FlutterPlatformViewFrames (flutter/flutter#196955)
2026-11-19 [email protected] Roll Skia from 0bf961e4ff05 to 2f1436ba8e64 (3 revisions) (flutter/flutter#196999)
2026-11-19 [email protected] [ios] Record OCMReject expectations before the stimulus in FlutterPluginAppLifeCycleDelegateTest (flutter/flutter#193011)
2026-11-19 [email protected] Fix post-monorepo doc rot in docs/infra and dev/bots/README.md (flutter/flutter#193010)
2026-11-19 [email protected] Roll Skia from c3567e170362 to 0bf961e4ff05 (4 revisions) (flutter/flutter#196994)
2026-11-19 [email protected] Close Linux popups when their parent loses focuses (flutter/flutter#196825)
2026-11-19 [email protected] Roll Packages from dca2e58 to 81b7c44 (6 revisions) (flutter/flutter#196992)
2026-11-19 [email protected] Roll Dart SDK from d8d40cf9c21b to 849e17ad3ae6 (1 revision) (flutter/flutter#196986)
2026-11-19 [email protected] Fix RouteObserver didPushNext not firing when routes are pushed synchronously (flutter/flutter#189057)
2026-11-19 [email protected] [Impeller] Reuse render targets on text shadow cache misses (flutter/flutter#194769)
2026-11-19 [email protected] Roll Skia from 81de64af9806 to c3567e170362 (3 revisions) (flutter/flutter#196982)
2026-11-19 [email protected] Reland: "Move macOS desktop builds to ThinLTO" (flutter/flutter#196928)
2026-11-19 [email protected] [Linux] Desynchronize the Wayland subsurface so frames don't redraw the GTK window (flutter/flutter#195287)
2026-11-19 [email protected] Roll Skia from 3dfb69d709c7 to 81de64af9806 (1 revision) (flutter/flutter#196975)
2026-11-19 [email protected] Update `ProxyAnimation.didStartListening` and `ProxyAnimation. didStopListening` to use dart's `Conditional member access` (flutter/flutter#195762)

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:
...
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 e: impeller Impeller rendering backend issues and features requests engine flutter/engine related. See also e: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Impeller] Text shadow cache miss allocates fresh blur render targets and evicts entries after one unused frame

3 participants