Skip to content

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

Closed

Description

@M0n7y5

What happens

On Impeller OpenGLES:

  • TextShadowCache::Lookup runs the Gaussian blur under RenderTargetCache::DisableCache() (text_shadow_cache.cc#L63-L67 on master). Each miss allocates, then frees, an MSAA color + depth-stencil pair and two blur textures per shadow.
  • MarkFrameEnd drops entries unused in that frame (text_shadow_cache.cc#L35-L38). Text whose glyphs cycle through a few states misses on every change.

Steps to reproduce

Profile build, scroll, count TexImage2DInitialization and render passes per frame on 1.raster in systrace.

import 'dart:async';
import 'package:flutter/material.dart';

const kShadows = [
  Shadow(color: Colors.black, blurRadius: 3),
  Shadow(color: Colors.black, blurRadius: 8),
];

void main() => runApp(MaterialApp(home: Repro()));

class Repro extends StatefulWidget {
  @override
  State<Repro> createState() => _ReproState();
}

class _ReproState extends State<Repro> {
  int tick = 0;

  @override
  void initState() {
    super.initState();
    Timer.periodic(const Duration(milliseconds: 33), (_) => setState(() => tick++));
  }

  @override
  Widget build(BuildContext context) => Scaffold(
        body: Column(children: [
          Expanded(
            child: ListView.builder(
              itemBuilder: (_, i) => ListTile(title: Text('Row $i')),
            ),
          ),
          Row(children: [
            const Text('Slowmode is enabled', style: TextStyle(shadows: kShadows)),
            Text(' ${tick % 4}'),
          ]),
          Text('Someone is typing${'.' * (tick % 4)}',
              style: const TextStyle(shadows: kShadows)),
        ]),
      );
}

Expected

Unchanged text hits. Changed text reuses same-size blur targets from RenderTargetCache.

Actual

moto g54 5G (PowerVR BXM-8-256, 120 Hz):

  • 3.47.7: both labels miss nearly every frame, 12 TexImage2DInitialization and 17 passes per frame.
  • 3.50 beta (with Started caching text shadows by content. #190681): the static label hits. Each change of the other label still allocates 2 MSAA renderbuffers + 6 textures and adds 8 passes.

Redmi Note 12 Pro 5G (Mali-G68): same per-frame counts on 3.47.7.

flutter doctor -v: Flutter 3.47.7, engine d8a2d6c768. Master a3d71d8 also reproduces from source.

Related

Fix in #194769.

Prepared with AI assistance.

Activity

  1. added
    engine
    c: performance
    has reproducible steps
    e: impeller
    team-engine
    on Oct 21, 2026
  2. mbcorona commented on Oct 21, 2026

    @mbcorona
    Member

    Hi @M0n7y5, thanks for the writeup, the repro, and the PR.
    Routing to team-engine.

  3. added
    P2
    on Oct 26, 2026
  4. gaaclarke commented on Oct 26, 2026

    @gaaclarke
    Member

    Do you have some quantifiable data that informs making this change?

  5. added
    triaged-engine
    on Oct 26, 2026
  6. M0n7y5 commented on Oct 29, 2026

    @M0n7y5
    ContributorAuthor

    Yes, from Perfetto traces on a moto g54 5G (PowerVR BXM-8-256, Impeller OpenGLES, 120 Hz), TexImage2DInitialization events and render passes counted per frame on the raster thread, plus release FrameTiming:

    scene baseline with #194769
    repro above, cycling two-shadow label (master vs master + PR) allocates in 26% of frames, 6 TexImage2D and 9 render passes at p90 0.1% of frames, 1 pass
    chat app, same labels over a scrolling list, release (3.47.7 vs master + PR) 406 allocating frames in the window, raster p50 5.94 ms 4 frames, 5.16 ms

    The chat row's baseline is the 3.47.7 release build, so part of its raster gain comes from master itself (#190681 and the GLES state dedup); the allocation count is the number that isolates this change. On a Redmi Note 12 Pro 5G (Mali-G68) the repro goes from raster p50 5.35 ms to 1.94 ms with the patched engine. Output is pixel-identical in both cases. The traces and the counting script are available if useful.

  7. added a commit that references this issue on Nov 19, 2026
    f586770
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2c: performancee: impellerenginehas reproducible stepsteam-enginetriaged-engine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions