Improving List performance with DisclosureGroup in large data sets

I have been pleased to see SwiftUI’s List performance improve over the years.

However, when using a List that contains DisclosureGroup views, expanding and collapsing items becomes significantly slower as the amount of data grows.

In my case, I need to control the initial expanded/collapsed state of each disclosure item, so I cannot use the recursive List(_:children:) API.

Is there a recommended way to improve the performance of a List containing DisclosureGroup views, or is falling back to AppKit’s NSOutlineView currently the only practical solution? (Yes, for context, my app is for macOS.)

The following code shows the relevant portion of my implementation:

List(self.summary.files, selection: $selection) { file in
    DisclosureGroup(isExpanded: $expandedFileURLs.contains(file.id)) {
        ForEach(file.matches) { match in
            FolderFindMatchView(match: match)
                .tag(FolderFind.ResultID.match(fileID: file.id, matchID: match.id))
        }
    } label: {
        FolderFindFileResultView(file: file)
            .draggable(item: FolderFindDraggedFile(id: .file(file.id), fileURL: file.fileURL))
    }
    .listRowSeparator(.hidden)
    .tag(FolderFind.ResultID.file(file.id))
}
Answered by Frameworks Engineer in 892346022

We've made improvements specifically for the performance of DisclosureGroup inside of List in macOS 27.0. I would recommend retesting on macOS 27.0 and filing feedback if you continue to see performance issues related to DisclosureGroup.

We've made improvements specifically for the performance of DisclosureGroup inside of List in macOS 27.0. I would recommend retesting on macOS 27.0 and filing feedback if you continue to see performance issues related to DisclosureGroup.

We've made improvements specifically for the performance of DisclosureGroup inside of List in macOS 27.0.

Wow! That’s great to hear! Thank you for making those improvements.

Lists and tables are still areas where SwiftUI can be challenging to use on macOS, so I always look forward to the performance improvements and API refinements that arrive each year.

In that case, my scenario may provide a useful test case. I’ll put together a detailed report and submit it through Feedback Assistant.

Improving List performance with DisclosureGroup in large data sets
 
 
Q