fix: disable anti aliasing for chart area#470
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideDisables anti-aliasing on the filled chart area gradient in the line series painter to adjust rendering behavior/performance. Class diagram for LinePainter change disabling anti aliasing on chart areaclassDiagram
class DataPainter {
}
class LinePainter {
+paint(canvas, size)
-createAreaPaint(size) Paint
}
class Paint {
+PaintingStyle style
+bool isAntiAlias
+Shader shader
}
DataPainter <|-- LinePainter
LinePainter ..> Paint : uses
%% Specific configuration for the chart area fill
class AreaPaintConfiguration {
+PaintingStyle style = fill
+bool isAntiAlias = false
+Shader gradientShader
}
LinePainter ..> AreaPaintConfiguration : configures
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Snapshot WarningsEnsure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice. OpenSSF Scorecard
Scanned Manifest Files |
|
Claude finished @behnam-deriv's task —— View job PR Review Complete ✅SummaryThis PR adds a single line to disable anti-aliasing for the line chart area fill. The change is minimal and focused, but there are some considerations worth discussing. Review Findings✅ Correctness & ImplementationLocation: The change is technically correct: final Paint areaPaint = Paint()
..style = PaintingStyle.fill
..isAntiAlias = false // ← Added line
..shader = ui.Gradient.linear(...)What this does: Disables anti-aliasing only for the area fill beneath line charts, not for the line itself (the line stroke still has anti-aliasing enabled by default). 🤔 Code Quality & Design ConsiderationsMedium Priority Issues:
🧪 TestingLow Priority:
Note: Visual changes like this typically require manual testing or golden file tests. Given the project doesn't have painter tests currently, this is consistent with the existing test coverage strategy. ⚡ PerformancePositive Impact:
🔒 SecurityNo security concerns. RecommendationsHigh PriorityNone - the change works as intended. Medium Priority
Low Priority
VerdictApproval Recommendation: ✅ Approve with suggestions The change is safe and likely improves rendering quality based on the PR description. The code functions correctly and follows the project's patterns. The medium-priority suggestions are about maintainability and configurability, not correctness. Quick Win: Add this comment at line 41: // Disable anti-aliasing to prevent smoothing artifacts at area boundaries
..isAntiAlias = false |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Disabling
isAntiAliason the areaPaintis a non-obvious choice that can affect visual quality, so it would be helpful to document the rationale (e.g. performance, artifact workaround) near this line to make the intent clear for future maintainers.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Disabling `isAntiAlias` on the area `Paint` is a non-obvious choice that can affect visual quality, so it would be helpful to document the rationale (e.g. performance, artifact workaround) near this line to make the intent clear for future maintainers.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
Claude finished @behnam-deriv's task —— View job PR Review Complete ✅This PR adds a single line to disable anti-aliasing for the line chart area fill. I've analyzed the change against correctness, code quality, performance, security, and testing criteria. Review Findings✅ Correctness & ImplementationLocation: The change is correct and solves the stated performance problem: final Paint areaPaint = Paint()
..style = PaintingStyle.fill
..isAntiAlias = false // ← Added line
..shader = ui.Gradient.linear(...)Why this works:
No regressions identified:
📊 Performance ImpactHIGH PRIORITY - POSITIVE The PR description's analysis is sound:
Expected impact: Substantial reduction in frame rendering time when Y-axis is zoomed in, with the improvement scaling proportionally to the visible vertical range. 🔍 Code Quality & DocumentationMEDIUM PRIORITY Issue: Missing inline documentation The change lacks a comment explaining the rationale. This is a non-obvious optimization that future maintainers might question or accidentally revert. Recommendation: final Paint areaPaint = Paint()
..style = PaintingStyle.fill
// Disable anti-aliasing to reduce GPU fill cost. The area edges are
// hidden beneath the stroke line, so AA provides no visual benefit.
..isAntiAlias = false
..shader = ui.Gradient.linear(This addresses the feedback from both Sourcery-AI and the previous Claude review. Per CLAUDE.md contribution guidelines: "Document non-obvious implementation decisions." 🎨 Design ConsiderationsLOW PRIORITY Observation: No configurability The anti-aliasing setting is now hardcoded. While this is appropriate for the common case (area beneath line), there's no way for users to override it if needed. Current state:
Analysis:
Verdict: Hardcoding is acceptable. Configuration can be added later if use cases emerge. 🧪 TestingLOW PRIORITY Findings:
Observation:
Recommendation: 🔒 SecurityNo concerns. This is a rendering optimization with no security implications. Summary & Recommendations✅ High Priority (Must Address)None - the implementation is correct and safe to merge.
|
fix: reduce CPU usage on line chart area fill during Y-axis zoom
Problem
High CPU usage was observed on the line chart when the Y-axis was zoomed in (vertical padding at minimum). The effect was noticeably worse the more zoomed in the chart was, and improved significantly when zoomed out to maximum padding.
Root cause
The investigation traced the bottleneck to
canvas.drawPathinLinePainter.onPaintData, specifically the area fill drawn beneath the line series.The area fill path is closed all the way down to the bottom of the canvas (
size.height). This means the filled polygon covers a pixel area proportional to how much vertical space the line occupies:canvas.drawPathwithPaintingStyle.fillmust rasterise every pixel inside the polygon. The cost scales directly with the number of pixels covered, so CPU usage rose and fell with the zoom level.Anti-aliasing compounded the cost. Flutter's rasteriser computes sub-pixel edge coverage for every boundary pixel of the filled polygon. For a large filled shape spanning hundreds of pixels vertically this is significant overhead.
The area fill edges are not visible to the user — they sit directly beneath the stroked line drawn on top — so anti-aliased edges on the fill provide no visual benefit.
Solution
Disabling anti-aliasing on the area fill paint:
Setting
isAntiAlias = falsetells the rasteriser to skip sub-pixel edge computation entirely and fill pixels with a hard cutoff. Since the stroke line already covers the fill boundary, the visual result is identical to the user while the per-frame GPU cost is substantially reduced regardless of zoom level.