Skip to content

[flutter_svg] Invalidate pending cache entries on clear and evict - #13595

Merged
auto-submit[bot] merged 2 commits into
flutter:mainfrom
palmoni5:codex/upstream-svg-cache-lifecycle
Nov 11, 2026
Merged

auto-submit[bot] merged 2 commits into
flutter:mainfrom
palmoni5:codex/upstream-svg-cache-lifecycle

Conversation

@palmoni5

@palmoni5 palmoni5 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Rebased on current main (8041ccab1), preserving the failed-load fix and its regression test from #13604. This PR adds invalidation of pending loads on Cache.clear and Cache.evict: an obsolete completion cannot repopulate the cache or remove a replacement request, even when loaders reuse the same Future.

Documents pending-load invalidation on both methods. The cache lifecycle tests live in cache_test.dart. The shared-Future regression checks that an evicted request does not populate the cache before the replacement's completion callback runs. Preserves synchronous cache hits, coalescing and entry-count LRU. Bumps the package to 2.3.4 with a changelog entry.

Related: flutter/flutter#182486 (failed-load cleanup is already on main via #13604).

Validation on Windows: flutter analyze clean; full flutter test suite: 77 passed, 1 existing skip; formatting and git diff --check passed. No golden files changed.

Overlapping proposals: #13613 also concerns failed pending loads; main already includes #13604. This PR retains that fix and focuses on clear/evict invalidation. #13596 is stacked on this branch and was rebased with it.

Pre-Review Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the AI contribution guidelines and understand my responsibilities, or I am not using AI tools.
  • I read the Tree Hygiene page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter.
  • I signed the CLA.
  • The title starts with the package name in square brackets.
  • I linked to at least one related issue above.
  • I followed the version and CHANGELOG instructions.
  • I updated relevant API documentation.
  • I added regression tests.
  • All existing and new tests are passing.

This draft was prepared with AI assistance and remains pending the contributor's human review and confirmation of the unchecked checklist items.

@github-actions github-actions Bot added p: flutter_svg triage-engine Should be looked at in engine triage labels Nov 9, 2026
@palmoni5
palmoni5 marked this pull request as ready for review November 9, 2026 13:45

@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 updates the flutter_svg package to version 2.3.3, introducing a _PendingLoad wrapper class in Cache to track the identity of in-flight loads. This change prevents stale or invalidated pending loads from repopulating the cache after a clear or evict operation, and ensures failed loads are removed from the pending cache to allow retries. Unit tests have been added to verify these cache lifecycle behaviors. There are no review comments, and I have no feedback to provide.

@zxdan-git zxdan-git 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 with nits.

@gaaclarke
gaaclarke self-requested a review November 11, 2026 01:05
@palmoni5
palmoni5 force-pushed the codex/upstream-svg-cache-lifecycle branch from 8757ae9 to a3d2a70 Compare November 11, 2026 08:20
@palmoni5 palmoni5 changed the title [flutter_svg] Retry failed loads and invalidate pending cache entries [flutter_svg] Invalidate pending cache entries on clear and evict Nov 11, 2026
@palmoni5
palmoni5 requested a review from zxdan-git November 11, 2026 08:25

@zxdan-git zxdan-git 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 thanks!

@gaaclarke gaaclarke added the CICD Run CI/CD label Nov 11, 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.

Mostly looking good. I think when you rebased you duplicated a test and I'm not sure why you've added _PendingLoad.

Comment on lines +173 to +194
test('failed loads are removed from the pending cache and can be retried', () async {
final cache = Cache();
final firstLoad = Completer<ByteData>();
final Future<ByteData> pending = cache.putIfAbsent('icon', () => firstLoad.future);

expect(
identical(pending, cache.putIfAbsent('icon', () => throw StateError('duplicate load'))),
isTrue,
);

final Future<void> expectedFailure = expectLater(pending, throwsStateError);
firstLoad.completeError(StateError('temporarily unavailable'));
await expectedFailure;

final recovered = ByteData(2);
final ByteData result = await cache.putIfAbsent(
'icon',
() => Future<ByteData>.value(recovered),
);
expect(identical(result, recovered), isTrue);
expect(cache.count, 1);
});

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. I removed the duplicate retry test and kept the upstream regression from #13604 in 16c7e6d.

@palmoni5
palmoni5 force-pushed the codex/upstream-svg-cache-lifecycle branch from a3d2a70 to 16c7e6d Compare November 11, 2026 19:05
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 11, 2026
@palmoni5
palmoni5 requested a review from gaaclarke November 11, 2026 19:07
@gaaclarke gaaclarke added the CICD Run CI/CD label Nov 11, 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 added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 11, 2026
@auto-submit
auto-submit Bot merged commit 5365902 into flutter:main Nov 11, 2026
14 checks passed
@palmoni5
palmoni5 deleted the codex/upstream-svg-cache-lifecycle branch November 11, 2026 21:11
b-luk pushed a commit to b-luk/flutter that referenced this pull request Nov 12, 2026
…r#196450)

flutter/packages@653628e...14f9933

2026-11-12 [email protected] [material_ui]
Fix SnackBarThemeData.lerp dropping showCloseIcon
(flutter/packages#13449)
2026-11-11 [email protected] [ci] Update repo
for 3.50 stable release (flutter/packages#13628)
2026-11-11 [email protected] [vector_graphics]
Use font-family lists as a family with fallbacks
(flutter/packages#13552)
2026-11-11 [email protected] Roll Flutter (stable) from
c197ca5 to ab29120 (1647 revisions) (flutter/packages#13625)
2026-11-11 [email protected] [shared_prferences] Adopts
mockito-kotlin in tests (flutter/packages#13624)
2026-11-11 [email protected] [cupertino_ui] Dim disabled
CupertinoSlider controls (flutter/packages#13419)
2026-11-11 [email protected] [flutter_svg] Invalidate pending cache
entries on clear and evict (flutter/packages#13595)
2026-11-11 [email protected] [cupertino_ui] Fix the tinted
button's fill opacity (flutter/packages#13436)
2026-11-11 [email protected] [various]
Support SVG filters (blur, offset, feMerge) (flutter/packages#11909)

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-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
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
auto-submit Bot pushed a commit that referenced this pull request Nov 12, 2026
Merged main (14f9933) in d01b5b2, preserving branch history. Main now contains the pending-load changes from #13595. The Files changed tab shows the byte-budget implementation, tests, and release metadata.

Adds a byte budget to the compiled SVG cache: Cache.maximumByteSize defaults to 32 MiB, Cache.currentByteSize reports retained compiled-data bytes, and completed entries obey both the existing count limit and the byte limit using LRU eviction. Oversized results are returned to callers without displacing cached entries. Reducing a limit evicts immediately; zero disables retention. Adds API documentation, regression tests, version 2.4.0 and changelog.

Related memory report: flutter/flutter#184564. This proposal bounds retained compiled cache data; it does not claim to solve the report's peak memory during compilation or memory retained by live widgets.

Validation on Windows: flutter analyze (no issues); complete flutter test suite (84 passed, 1 pre-existing skip); formatting and git diff --check. Tests cover byte/count LRU, changing limits, oversized results, out-of-order completions, and disabling/re-enabling during pending loads. Small platform golden differences are accepted by the existing comparator; no goldens were updated.

## Pre-Review Checklist

This draft was prepared with AI assistance and remains pending the contributor's human review and confirmation of the unchecked checklist items.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD p: flutter_svg triage-engine Should be looked at in engine triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants