Skip to content

perf: replace Decimal arithmetic in expand layout with doubles (#121)#132

Open
andyhorn wants to merge 1 commit into
mainfrom
optimize-layout-arithmeti
Open

perf: replace Decimal arithmetic in expand layout with doubles (#121)#132
andyhorn wants to merge 1 commit into
mainfrom
optimize-layout-arithmeti

Conversation

@andyhorn
Copy link
Copy Markdown
Owner

Summary

  • Replaces Decimal math in _getExpandSizes with native double arithmetic. The Decimal-based loop ran Decimal.parse(toString()) conversions on every layout pass and allocated on every operation; pixel layout doesn't need rational precision.
  • Algorithm structure (iterative clamp + redistribute) is unchanged. Iteration is bounded by expandIndices.length + 2 to defend against FP residue keeping didChange=true.
  • Drops the decimal dependency from pubspec.yaml and removes the now-unused toDecimal() extension.

Closes #121.

Test plan

  • flutter analyze — clean
  • flutter test — all tests pass (expand math tests use exactly-representable values: 198, 398, 300, 100, 500; no rounding fixup needed)

🤖 Generated with Claude Code

`_getExpandSizes` ran allocation-heavy Decimal math on every layout pass,
with `Decimal.parse(toString())` conversions inside the iteration loop.
Pixel layout doesn't need rational precision, so this swaps the inner
loop to native double arithmetic and bounds iteration count to defend
against floating-point residue. Drops the `decimal` dependency.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.

Decimal arithmetic in performLayout is expensive

1 participant