SwiftUI makes building interfaces remarkably straightforward. However, understanding how and when SwiftUI updates views is an important part of building performant applications.

Have you ever wondered why a SwiftUI view gets updated even though the property it displays hasn't changed?

This behavior becomes particularly interesting when multiple views observe the same ObservableObject.

In this article, I'll demonstrate a small experiment that reproduces unnecessary view updates, explain why they happen, and show how Swift's @Observable macro helps reduce unnecessary rendering work.

I've also created a sample project called Redraw Lab so you can reproduce the experiment yourself.

GitHub Repository: https://github.com/raviseta/SwiftUI-Performance-measurement

1. Understanding the problem

Consider a dashboard containing three independent cards:

  • Workspace
  • Ticker
  • Projects

Each card reads a different property from the same data store.

final class LegacyDashboardStore: ObservableObject { @Published var workspaceName = "Acme Design Team" @Published var projects = [ "Onboarding revamp", "Billing v2", "Dark mode polish" ] @Published var tick = 0 } 

Now imagine that tick changes approximately 60 times per second.

The Workspace card doesn't depend on tick. Neither does the Projects card.

However, because all three views observe the same ObservableObject, changes published by that object can invalidate all three views.

This means SwiftUI may recalculate view bodies even when their displayed data hasn't changed.

That's unnecessary work.

2. Why does ObservableObject cause this?

Consider this simplified view:

struct LegacyWorkspaceCard: View { @ObservedObject var store: LegacyDashboardStore var body: some View { Text(store.workspaceName) } } 

The view only reads workspaceName.

However, ObservableObject exposes a shared objectWillChange publisher.

When a published property changes, observers of that object receive the change notification.

SwiftUI doesn't automatically narrow that notification to only the specific property read by each view.

As a result, unrelated views can be invalidated.

The issue becomes more noticeable when:

  • A shared observable object contains many properties.
  • Several views depend on that object.
  • Some properties change frequently.
  • View bodies perform expensive calculations.

3. The solution: @observable

Swift introduced the Observation framework, which provides a more granular way to track dependencies.

Instead of using ObservableObject and @Published, we can use the @Observable macro.

@Observable final class DashboardStore { var workspaceName = "Acme Design Team" var projects = [ "Onboarding revamp", "Billing v2", "Dark mode polish" ] var tick = 0 } 

The Workspace card becomes:

struct WorkspaceCard: View { let store: DashboardStore var body: some View { Text(store.workspaceName) } } 

SwiftUI tracks the properties accessed while evaluating the view body.

Now, when tick changes, the Workspace and Projects cards don't need to update because neither depends on that property.

Only the views that actually depend on the changing property are invalidated.

4. Before and after comparison

Here is what the experiment demonstrates:

Observation ObservableObject @observable
Workspace card Re-renders No unnecessary update
Ticker card Re-renders Re-renders
Projects card Re-renders No unnecessary update
Property-level tracking No Yes

The important distinction is that the ticker should continue updating. That's expected behavior.

The optimization is about preventing unrelated views from updating.

5. Measuring performance with Xcode Instruments

I didn't want to rely only on visual observations or render counters.

I wanted to verify the behavior using Xcode Instruments.

The project includes a reproducible profiling workflow.

Step 1: Profile a Release build

Open the project in Xcode.

Press:

Command + I

Choose the SwiftUI profiling template.

The project is configured to profile using Release.

For meaningful measurements, prefer testing on a physical device.

Step 2: Record both implementations

The dashboard includes a switch between:

Record approximately six seconds with ObservableObject selected.

Then switch to @observable and record another six seconds.

This gives you a before-and-after comparison in one trace.

Step 3: Inspect Long View Body Updates

Open the SwiftUI timeline in Instruments.

Look at the Long View Body Updates lane.

In the experiment, unnecessary workspace and projects updates are visible before switching to @observable.

After switching, those unrelated updates disappear.

Step 4: Inspect the update details

Select a time range and inspect the View Body Updates table.

Compare which views execute in each implementation.

You can also inspect the Root Causes column to understand what triggered an update.

This is particularly useful because it helps explain not only which views updated, but why.

6. Actual measurements from the experiment

Here are the results from my Release-build experiment:

Metric ObservableObject @observable
View bodies executed per tick 13 4
Workspace card body ~615 µs Not executed
Projects card body ~915 µs Not executed
Ticker card body ~13 µs ~40 µs

The workspace and projects cards intentionally perform simulated work using a busy-wait operation.

This makes unnecessary updates easier to identify in Instruments.

The ticker's small timing difference is run-to-run noise, not a performance regression caused by @observable.

These numbers are specific to this experiment and will vary across devices and execution environments.

7. Bonus: Debugging with Self._printChanges()

Instruments is useful for runtime analysis, but SwiftUI also provides a debugging technique that helps understand why a view is being invalidated.

You can use:

Self._printChanges() 

Place it inside a view's body during debugging.

For an additional debugging setup, enable the following launch argument:

-printChanges YES 

In Xcode:

  1. Open Product → Scheme → Edit Scheme.
  2. Select Run.
  3. Open Arguments.
  4. Add -printChanges YES.
  5. Run the app using a Debug build.

In this experiment, the console shows that the legacy Workspace card changes because its observed store changed, even though it doesn't read the frequently changing tick property.

This provides another way to investigate unexpected view updates.

8. What I learned

This experiment reinforced a few important SwiftUI performance principles:

  1. A view update isn't necessarily expensive, but unnecessary updates can accumulate.
  2. Shared observable objects can introduce broader dependencies than intended.
  3. Property-level observation can reduce unnecessary invalidation.
  4. Render counters are useful for understanding behavior, but they aren't substitutes for performance profiling.
  5. Instruments provides evidence that helps distinguish actual performance improvements from assumptions.

Most importantly, optimization should start with measurement.

Changing code because a pattern looks inefficient doesn't guarantee that the application will become faster.

9. Explore the complete project

I created Redraw Lab as a small, focused learning project.

It requires Xcode 26 or later and iOS 26 or later, and has no external dependencies.

The repository includes:

  • Complete SwiftUI implementation.
  • ObservableObject and @observable examples.
  • Render counters.
  • Simulated workload.
  • Instruments profiling instructions.
  • Before-and-after measurement details.
  • Debugging instructions.

GitHub Repository: https://github.com/raviseta/SwiftUI-Performance-measurement

Final thoughts

SwiftUI performance isn't just about making views render faster. It's also about understanding the dependency relationships that determine when views need to update.

The Observation framework gives us a more granular approach to tracking those dependencies.

If you're building SwiftUI applications, I encourage you to experiment with Instruments and understand what your views are actually doing.

I'd love to hear about your experiences.

How do you investigate unnecessary view updates in your SwiftUI applications?

SwiftUI #iOSDevelopment #Swift #PerformanceOptimization #AppleDevelopment