Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance problem #19

Open
c941010623 opened this issue Dec 22, 2019 · 4 comments
Open

Performance problem #19

c941010623 opened this issue Dec 22, 2019 · 4 comments

Comments

@c941010623
Copy link

c941010623 commented Dec 22, 2019

i see your code

return ScrollView(style.scrollDirection) {
            ZStack(alignment: .topLeading) {
                ForEach(data, id: self.dataId) { element in
                    self.content(element)
                        .frame(width: self.style.scrollDirection == .vertical ? columnWidth : nil,
                               height: self.style.scrollDirection == .horizontal ? columnWidth : nil)
                        .background(PreferenceSetter(id: element[keyPath: self.dataId]))
                        .alignmentGuide(.top, computeValue: { _ in self.alignmentGuides[element[keyPath: self.dataId]]?.y ?? 0 })
                        .alignmentGuide(.leading, computeValue: { _ in self.alignmentGuides[element[keyPath: self.dataId]]?.x ?? 0 })
                        .opacity(self.alignmentGuides[element[keyPath: self.dataId]] != nil ? 1 : 0)
                }
            }
            .padding(style.padding)
            .frame(maxWidth: .infinity, maxHeight: .infinity)
            .animation(self.loaded ? self.style.animation : nil)
        }

i think your ForEach can change use List
because when image count > 300 pic, use List can Recycle reuse

What do you think ??

@Elshad
Copy link

Elshad commented Dec 27, 2019

List is UITableView. There is not UICollectionView alternative for SwiftUI.
And i think there will be always performance problem with waterfall grid, because to define frame of 10_000th cell you must know frames of 9_999 previous cell. Think about 100_000, 1_000_000 and etc

@c941010623
Copy link
Author

You are right

@paololeonardi
Copy link
Owner

paololeonardi commented Dec 28, 2019

@c941010623, I'm glad you brought up the performance topic.

There is indeed an issue with a large number of elements and @Elshad has already described one of the reasons behind it.
Also, the grid uses SwiftUI ZStack which doesn't have a concept of reuse of the elements. All the grid views need to be created upfront and kept in memory even if not visible on screen.

For the kind of layout we want to achieve, the use of List is not a solution here.
WaterfallGrid, ZStack, HStack and VStack play well with just a small/medium number of Views.

To be able to scale I believe we have to wait for a UICollectionView alternative for SwiftUI.
But open for ideas.

Thank you both!

@sindresorhus
Copy link

LazyVStack could maybe be used when available to improve performance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants