# Introducing Equatable: package that provides macros for generating Equatable conformances for structs for high performance SwiftUi view diffing

**URL:** <https://forums.swift.org/t/introducing-equatable-package-that-provides-macros-for-generating-equatable-conformances-for-structs-for-high-performance-swiftui-view-diffing/80924>\
**Category:** Community Showcase\
**Tags:** swiftui, macros\
**Created:** [July 5, 2025, 10:08am UTC](https://forums.swift.org/t/introducing-equatable-package-that-provides-macros-for-generating-equatable-conformances-for-structs-for-high-performance-swiftui-view-diffing/80924 "2025-07-05T10:08:28Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![supersonicbyte](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/supersonicbyte/32/38419_2.png) [@supersonicbyte](https://forums.swift.org/u/supersonicbyte)\
**Post date:** [July 5, 2025, 10:08am UTC](https://forums.swift.org/t/introducing-equatable-package-that-provides-macros-for-generating-equatable-conformances-for-structs-for-high-performance-swiftui-view-diffing/80924/1 "2025-07-05T10:08:28Z")

</div>

Cal Stephens (@cal) wrote an excellent blog post, [**Understanding and Improving SwiftUI Performance**](https://medium.com/airbnb-engineering/understanding-and-improving-swiftui-performance-37b77ac61896).

The post gives us insight into how SwiftUI’s performance hinges on efficient view diffing—but the default behavior often falls short, especially with closures and complex view models. Manually writing `Equatable` conformances is tedious and error-prone.

An `Equatable` macro is introduced to solve this by generating optimized `Equatable` implementations for your SwiftUI views, ensuring accurate and performant diffing out of the box. It eliminates boilerplate, prevents regressions, and helps you avoid unnecessary re-renders—boosting UI performance while keeping your codebase clean and maintainable.

Ideal for teams scaling SwiftUI in large apps.

We at [Ordo One](https://ordo.one/) decided to implement the macro and [open-source](https://github.com/ordo-one/equatable) it for the community.

## Usage

Apply the `@Equatable` macro to structs to automatically generate `Equatable` conformance:

```swift
import Equatable
import SwiftUI

@Equatable
struct ProfileView: View {
    var username: String // Will be compared
    @State private var isLoading = false // Automatically skipped
    @ObservedObject var viewModel: ProfileViewModel // Automatically skipped
    @EquatableIgnored var cachedValue: String? // This property will be excluded
    @EquatableIgnoredUnsafeClosure var onTap: () -> Void // This closure is safe and will be ignored in comparison (in order for it to be safe we must be sure that this closure does not capture value types on call site)
    let id: UUID // Will be compared first for short-circuiting equality checks
    
    var body: some View {
        VStack {
            Text(username)
            if isLoading {
                ProgressView()
            }
        }
    }
}

```

The generated extension will implement the `==` operator with property comparisons ordered for optimal performance (e.g., IDs and simple types first):

```swift
extension ProfileView: Equatable {
    nonisolated public static func == (lhs: ProfileView, rhs: ProfileView) -> Bool {
        lhs.id == rhs.id && lhs.username == rhs.username
    }
}

```

We would love to hear your feedback!

---

<div class="post-metadata">

**Author:** ![nikola](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nikola/32/45872_2.png) [@nikola](https://forums.swift.org/u/nikola)\
**Post date:** [July 5, 2025, 11:19pm UTC](https://forums.swift.org/t/introducing-equatable-package-that-provides-macros-for-generating-equatable-conformances-for-structs-for-high-performance-swiftui-view-diffing/80924/2 "2025-07-05T23:19:35Z")

</div>

Nice! Looking forward to taking this library for a spin. 👏

Also: IIUC, it's also necessary to wrap a view in a [EquatableView](https://developer.apple.com/documentation/swiftui/equatableview) (or the shorthand [equatable()](https://developer.apple.com/documentation/swiftui/view/equatable()) modifier) so as to opt out of SwiftUI’s built-in reflection-based diffing.

---

<div class="post-metadata">

**Author:** ![Jon\_Shier](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jon_shier/32/921_2.png) [@Jon\_Shier](https://forums.swift.org/u/Jon_Shier)\
**Post date:** [July 5, 2025, 11:56pm UTC](https://forums.swift.org/t/introducing-equatable-package-that-provides-macros-for-generating-equatable-conformances-for-structs-for-high-performance-swiftui-view-diffing/80924/3 "2025-07-05T23:56:49Z")

</div>

I would suggest renaming this to `EquatableView`, both for clarity, and also because it becomes the obvious name if you add `.equatable()` using the macro.

---

<div class="post-metadata">

**Author:** ![cal](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/cal/32/35557_2.png) [@cal](https://forums.swift.org/u/cal)\
**Post date:** [July 6, 2025, 1:38am UTC](https://forums.swift.org/t/introducing-equatable-package-that-provides-macros-for-generating-equatable-conformances-for-structs-for-high-performance-swiftui-view-diffing/80924/4 "2025-07-06T01:38:46Z")

</div>

This isn't necessary -- SwiftUI automatically uses an `Equatable` conformance if present rather than the default reflection-based comparison algorithm.

If a view is POD, then SwiftUI will compare the bits directly rather than using the `Equatable` conformance. However, POD views are pretty uncommon\[1\], and if your view is POD then you shouldn't be needing to use `@EquatableIgnored` in the view anyway.

* * *

1. Any SwiftUI property wrapper like `@State` makes a view not be POD, in addition to non-POD types like `String`, `Array`, `Dictionary` (all copy-on-write reference types under the hood), or any other reference type. Views without any of these are pretty uncommon and probably don't need to be optimized with `@Equatable`.

---

<div class="post-metadata">

**Author:** ![hassila](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/hassila/32/22647_2.png) [@hassila](https://forums.swift.org/u/hassila)\
**Post date:** [July 6, 2025, 7:14am UTC](https://forums.swift.org/t/introducing-equatable-package-that-provides-macros-for-generating-equatable-conformances-for-structs-for-high-performance-swiftui-view-diffing/80924/5 "2025-07-06T07:14:59Z")

</div>

We will be using this for non-SwiftUI use cases too, so such renaming would be misleading - it is clearly useful for SwiftUI - but there are other uses too…

---

<div class="post-metadata">

**Author:** ![nikola](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nikola/32/45872_2.png) [@nikola](https://forums.swift.org/u/nikola)\
**Post date:** [July 6, 2025, 11:59am UTC](https://forums.swift.org/t/introducing-equatable-package-that-provides-macros-for-generating-equatable-conformances-for-structs-for-high-performance-swiftui-view-diffing/80924/6 "2025-07-06T11:59:55Z")

</div>

Thanks for clarifying. Then I'm struggling to see a use case where one would reach for a `EquatableView`. This view appears to be a relic of the early SwiftUI days and seems ripe for deprecation...

---

<div class="post-metadata">

**Author:** ![cal](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/cal/32/35557_2.png) [@cal](https://forums.swift.org/u/cal)\
**Post date:** [July 6, 2025, 3:41pm UTC](https://forums.swift.org/t/introducing-equatable-package-that-provides-macros-for-generating-equatable-conformances-for-structs-for-high-performance-swiftui-view-diffing/80924/7 "2025-07-06T15:41:16Z")

</div>

Speaking of non-SwiftUI use cases, the [SwiftFormat `redundantEquatable` rule](https://github.com/nicklockwood/SwiftFormat/blob/main/Rules.md#redundantequatable) can automatically adopt your `@Equatable` macro on classes in your project:

```diff
  // Using --equatable-macro @Equatable,MyMacroLib
  import FooLib
+ import MyMacroLib

+ @Equatable
+ class Bar {
- class Bar: Equatable {
      let baaz: Baaz

- static func ==(lhs: Bar, rhs: Bar) -> Bool {
- lhs.baaz == rhs.baaz
- }
  }

```

---

<div class="post-metadata">

**Author:** ![mbrandonw](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mbrandonw/32/349_2.png) [@mbrandonw](https://forums.swift.org/u/mbrandonw)\
**Post date:** [July 6, 2025, 11:06pm UTC](https://forums.swift.org/t/introducing-equatable-package-that-provides-macros-for-generating-equatable-conformances-for-structs-for-high-performance-swiftui-view-diffing/80924/8 "2025-07-06T23:06:55Z")

</div>

> [@hassila](#):
>
> We will be using this for non-SwiftUI use cases too, so such renaming would be misleading - it is clearly useful for SwiftUI - but there are other uses too…

If that's the case, then I think that while this library is focused only on `Equatable`, you unfortunately are forced to also support `@Hashable`. Otherwise it's possible to do something seemingly innocuous that is hiding a problem:

```swift
@Equatable
struct User: Hashable {
  let id: Int 
  @EquatableIgnored
  var name = ""
}

```

In this type:

```swift
let userA = User(id: 1, name: "Blob")
let userB = User(id: 1, name: "Blob Jr")
userA == userB // ✅ true 
userA.hashValue == userB.hashValue // 🛑 false

```

This can lead to all types of problems, including runtime crashes, due to the hash invariant not being upheld.

---

<div class="post-metadata">

**Author:** ![hassila](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/hassila/32/22647_2.png) [@hassila](https://forums.swift.org/u/hassila)\
**Post date:** [July 7, 2025, 6:30am UTC](https://forums.swift.org/t/introducing-equatable-package-that-provides-macros-for-generating-equatable-conformances-for-structs-for-high-performance-swiftui-view-diffing/80924/9 "2025-07-07T06:30:00Z")

</div>

Good catch for the general case, thanks!

> <https://github.com/ordo-one/equatable/issues/12>
>
> See https://forums.swift.org/t/introducing-equatable-package-that-provides-macro…s-for-generating-equatable-conformances-for-structs-for-high-performance-swiftui-view-diffing/80924/8
> 
> TLDR:
> 
> The automatically synthesized hashable implementation can mismatch the Equatable implementation otherwise.

---

<div class="post-metadata">

**Author:** ![Cecilie](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@Cecilie](https://forums.swift.org/u/Cecilie)\
**Post date:** [July 7, 2025, 6:46am UTC](https://forums.swift.org/t/introducing-equatable-package-that-provides-macros-for-generating-equatable-conformances-for-structs-for-high-performance-swiftui-view-diffing/80924/10 "2025-07-07T06:46:32Z")

</div>

Yes itis heplful for us

---

<div class="post-metadata">

**Author:** ![Cecilie](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@Cecilie](https://forums.swift.org/u/Cecilie)\
**Post date:** [July 7, 2025, 6:49am UTC](https://forums.swift.org/t/introducing-equatable-package-that-provides-macros-for-generating-equatable-conformances-for-structs-for-high-performance-swiftui-view-diffing/80924/11 "2025-07-07T06:49:05Z")

</div>

Very helpful

---

<div class="post-metadata">

**Author:** ![hassila](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/hassila/32/22647_2.png) [@hassila](https://forums.swift.org/u/hassila)\
**Post date:** [July 7, 2025, 3:57pm UTC](https://forums.swift.org/t/introducing-equatable-package-that-provides-macros-for-generating-equatable-conformances-for-structs-for-high-performance-swiftui-view-diffing/80924/12 "2025-07-07T15:57:02Z")

</div>

Thanks again, sorted now with 1.0.4 / [feat(patch): generate correct implementation if type conforms to by supersonicbyte · Pull Request #13 · ordo-one/equatable · GitHub](https://github.com/ordo-one/equatable/pull/13)

---

<div class="post-metadata">

**Author:** ![supersonicbyte](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/supersonicbyte/32/38419_2.png) [@supersonicbyte](https://forums.swift.org/u/supersonicbyte)\
**Post date:** [September 30, 2025, 9:39am UTC](https://forums.swift.org/t/introducing-equatable-package-that-provides-macros-for-generating-equatable-conformances-for-structs-for-high-performance-swiftui-view-diffing/80924/13 "2025-09-30T09:39:44Z")

</div>

With [1.1.0](https://github.com/ordo-one/equatable/releases/tag/1.1.0) release, `Equatable macro` supports generating the conformance with different isolation levels by using the `isolation` parameter. The parameter accepts three values: `.nonisolated` (default), `.isolated`, and .`main` (requires Swift 6.2 or later). The chosen isolation level will be applied to the generated conformances for both` Equatable` and `Hashable` (if applicable).

**Nonisolated (default)**

The generated `Equatable` conformance is `nonisolated`, meaning it can be called from any context without isolation guarantees.

```swift

@Equatable(isolation: .nonisolated) (also omitting the parameter uses this mode)
struct Person {
    let name: String
    let age: Int
}

expands to:

extension Person: Equatable {
  nonisolated public static func == (lhs: Person, rhs: Person) -> Bool {
    lhs.name == rhs.name && lhs.age == rhs.age
  }
}

```

**Isolated**

The generated `Equatable` conformance is `isolated`, meaning it can only be called from within the actor's context.

```swift

@Equatable(isolation: .isolated)
struct Person {
    let name: String
    let age: Int
}

expands to:

extension Person: Equatable {
  public static func == (lhs: Person, rhs: Person) -> Bool {
    lhs.name == rhs.name && lhs.age == rhs.age
  }
}

```

**Main** (requires Swift 6.2 or later)

A common case is to have a `@MainActor` isolated type, SwiftUI views being a common example. Previously, the generated `Equatable` conformance had to be `nonisolated` in order to satisfy the protocol requirement. This would then restrict us to access only nonisolated properties of the type in the generated `Equatable` function — which meant that we had to ignore all `@MainActor` isolated properties in the equality comparison. Swift 6.2 introduced [isolated conformances]( [Documentation](https://docs.swift.org/compiler/documentation/diagnostics/isolated-conformances/) ) allowing us to generate `Equatable` conformances which are bound to the `@MainActor`. In this way the generated `Equatable` conformance can access `@MainActor` isolated properties of the type synchronously and the compiler will guarantee that the conformance will be called only from the `@MainActor` context.

We can do so by specifying `@Equatable(isolation: .main)`, e.g: `

```swift

@Equatable(isolation: .main)
@MainActor
struct Person {
    let name: String
    let age: Int
}

expands to:

extension Person: @MainActor Equatable {
    public static func == (lhs: Person, rhs: Person) -> Bool {
        lhs.name == rhs.name && lhs.age == rhs.age
    }
}

```
