Skip to content

feat!: Remove integralSize property from class Svg, enforcing 'always true' behaviour - #3969

Merged
spydon merged 2 commits into
flame-engine:mainfrom
adario:feat/integral-sized-svg
Jul 24, 2026
Merged

feat!: Remove integralSize property from class Svg, enforcing 'always true' behaviour#3969
spydon merged 2 commits into
flame-engine:mainfrom
adario:feat/integral-sized-svg

Conversation

@adario

@adario adario commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Description

The Svg.integralSize property was added in PR #3956: when true, it ensures that the keys for Svg._imageCache are always integer-sized. The property, however, would never be useful with its current default of false, since this would re-introduce floating-point rounding errors in the image cache keys.

Resolution

Remove the integralSize property, always following its true codepath.

Testing

An updated testbed for the changes is available — this displays 200+1 SvgComponent objects, all with different rotation/scale values; it now features the Svg button, which cycles through a few SVG assets.
For comparison purposes, the testbed starts with the default implementation; the Mode and Size buttons cycle through several combinations of the fixedRatio and cacheSize properties..

Checklist

  • I have followed the Contributor Guide when preparing my PR.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • I have updated/added relevant examples in examples or docs.

Breaking Change?

  • Yes, this PR is a breaking change.
  • No, this PR is not a breaking change.

Migration instructions

This PR does change the internal caching behaviour in class Svg, for all rendering operations. However, any existing use cases of class Svg should build as previously , since the property changes from PR #3956 haven't been published yet. All parameters/properties from PR #3956 have default values, so no build should break.
At runtime, the PR should not break class Svg clients either: the actual Image objects in the MemoryCache should maintain the previous dimensions and contents, since these were already integral prior to PR #3956. A 3-way comparison for the melos test --scope=flame_svg results reveals no differences (all tests fail in the same way)...

I apologise if I've missed something, but at present I wouldn't know what migration steps to provide.

Related Issues

@spydon
spydon requested a review from Copilot July 23, 2026 12:10

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

Thanks for your contribution!

Copilot AI 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.

Pull request overview

This PR removes the Svg.integralSize API from flame_svg and makes Svg always use an “integral” cache-key strategy, aiming to prevent cache thrashing caused by floating-point rounding when rendering SVGs at varying scales/zooms.

Changes:

  • Removed the integralSize constructor/loader parameter and the corresponding public getter/setter from Svg.
  • Updated Svg.load, Svg.loadFromString, and Game.loadSvg to no longer accept/forward integralSize.
  • Simplified _getImage to always build the cache key from ceiled dimensions (now unconditional).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 161 to 165
Image _getImage(Size size, double widthRatio, double heightRatio) {
final width = size.width * widthRatio;
final height = size.height * heightRatio;
Size cacheKey;
if (fixedRatio || integralSize) {
cacheKey = Size(width.ceilToDouble(), height.ceilToDouble());
} else {
cacheKey = Size(width, height);
}
final cacheKey = Size(width.ceilToDouble(), height.ceilToDouble());
final image = _imageCache.getValue(cacheKey);
Comment on lines 13 to 16
/// Creates an [Svg] with the received [pictureInfo].
/// Default [pixelRatio] is the device pixel ratio.
/// Setting [integralSize] to `true` uses integer dimensions for cache keys.
/// Setting [fixedRatio] to `true` ensures the cache uses a single entry.
/// Default [cacheSize] is [defaultCacheSize], which is 10 as previously;
@adario

adario commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for your contribution!

Thank you. :-)
I'll have a look at Copilot's comments.

@adario

adario commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for your contribution!

Thank you. :-) I'll have a look at Copilot's comments.

@spydon — regarding this one, I've updated the dartdoc.

This one, while obviously valid, as expected costs quite a bit... the testbed shows ~35% increased cache usage (~170 instead of ~110 entries): after all, pixelRatio wasn't used for the cache keys prior to PR #3956 either.

Running image diffs on a few rendering results hasn't revealed any rasterisation improvements; the deltas all appear to be < 1%, and they mostly occur in the alpha channel. Anyways, the cache changes would formally align the keys with the contents' dimensions, so... please let me know whether I should add them to the PR.

(From a 'field usage' POV, the suggested approach would be what the testbed does: when Svg.fixedRatio is set to truewith the Mode button, and all SvgComponent objects share the same size property, Svg._imageCache only ever contains a single entry.This still allows to use whatever dimensions for any SvgComponent via the scale property, and whatever rotation via the angle property.)

@spydon

spydon commented Jul 23, 2026

Copy link
Copy Markdown
Member

@adario hmm, I'll let you decided, both are fine for me.

@adario

adario commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

@adario hmm, I'll let you decided, both are fine for me.

Thanks again: I think we could merge the PR, and revisit the Copilot changes at a later time... I've stashed them just in case.

@spydon
spydon merged commit fa78820 into flame-engine:main Jul 24, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants