NEW Tool! SwiftFairy: Local Swift and SwiftUI code reviews for your coding agent. Learn more ...NEW Tool! SwiftFairy:Local code reviews for your agents. Learn more...
← All SwiftFairy Scrolls

SwiftFairy Scroll

Performant Swift Charts

Improve rendering and interaction performance by structuring charts and surrounding views to limit unnecessary updates and use Swift Charts APIs effectively.

What your agent can improve

Chart structure

Help your agent structure charts and surrounding views to avoid updates that do not affect the chart.

Rendering performance

Identify API choices that introduce unnecessary rendering work and give your agent guidance to address them.

Responsive interactions

Find interaction state changes that trigger unnecessary chart updates, helping your agent keep interactions responsive.

Example findings

These examples show the patterns SwiftFairy flags and the guidance your agent can use to address them. Highlighted lines mark the code to review; each finding indicates whether the guidance is a requirement, recommendation, or consideration.

Consider

Preserve missing-data semantics

When a measurement is missing, substituting zero changes what the chart communicates. The appropriate representation depends on whether the chart draws independent marks or connects neighboring observations.

Pattern flagged for review

BarMark(
     x: .value("Date", reading.date),
     y: .value(
         "Temperature",
         reading.temperature ?? 0
     )
)

AreaMark(
     x: .value("Date", reading.date),
     y: .value(
         "Temperature",
         reading.temperature ?? 0
     )
)

A possible improvement

if let temperature = reading.temperature {
     BarMark(
         x: .value("Date", reading.date),
         y: .value(
             "Temperature",
             temperature
         )
     )
}

AreaMark(
     x: .value("Date", reading.date),
     y: .value(
         "Temperature",
         reading.temperature ?? Double.nan
     )
)

For independent bars, omit the mark when its measurement is missing. For an area chart, retain the observation and use Double.nan for the missing value to break the area across the gap. Removing the observation would connect its neighbors.

Consider

Use consistent semantic labels

When observations represent the same variable, their semantic label should remain consistent. Each observation's value belongs in the second argument to .value, rather than being interpolated into its label.

Pattern flagged for review

BarMark(
     x: .value("Date", reading.date),
     y: .value("Temperature", reading.temperature)
)
.foregroundStyle(by:
    .value(
      "Status \(reading.status)",
      reading.status
    )
)

A possible improvement

.foregroundStyle(
     by: .value("Status", reading.status)
)

Use a consistent dimension label and pass the observation's status as the value. Whether a dynamic label is appropriate depends on the intended semantics.

Put the findings to work

Ask your agent to review a code change or a complete codebase with SwiftFairy. Your agent uses the findings and their accompanying code examples to resolve issues in your code.

How to use SwiftFairy

Try Performant Swift Charts free for one day

Activate your trial in the SwiftFairy app. No card or payment information is required.

Choose lifetime access, a fixed term, or a subscription for this Scroll, or get all three together in a bundle.

Explore the other Scrolls