How to fix slow List updates in SwiftUI

Поделиться
HTML-код
  • Опубликовано: 13 окт 2024
  • If you have a SwiftUI list with lots of rows, you might find it's really slow to update when you sort or filter those rows - code that should run instantly might take one or two seconds, or if you have lots of items one or two minutes.
    In this video I’m going to show you what code causes the problem, then show you the one line of SwiftUI code that fixes it, and finally the most important part: explain why the problem occurs so you aren't just adding code without understanding it.
    You can find my free 100 Days of SwiftUI course here: hackingwithswift.com/100/swiftui

Комментарии • 37

  • @twostraws
    @twostraws  4 года назад +1

    Watch next: How to use neumorphism in SwiftUI - ruclips.net/video/z3tJdxwlo_Y/видео.html
    Questions? Comments? Tweet me @twostraws.

  • @AntonJazz
    @AntonJazz 2 года назад

    This is one of your best videos ever! It never occurred to me that the slowdown was in the List comparison for animation and not in the sorting/filtering itself. Bravo!!

  • @ChristopheBraud
    @ChristopheBraud 4 года назад +2

    It is not really a fix but more of a trick. SwiftUI is really excellent to manage animations and effects. To make detailed views or manage fixed lists of items it is also very good. But when it comes to manage large/dynamic lists of items it lacks basic mechanisms such as infinite scroll. I hope with the next version of SwiftUI Apple we will add this kind of feature builtin.

  • @mc7h_
    @mc7h_ 4 года назад +3

    Incredible series of Paul! thanks for everything you give to the community.

  • @kh-xl6vw
    @kh-xl6vw 4 года назад +3

    Love your videos. 👍🏻
    Just one more thing to point out is memory.
    The Issue code started at 14mb then up to 64mb and stayed there. Never moved up/down for the repeated shuffles. Why the jump?
    The solved code it too started at 14mb but then increased 2mb every button click it seemed and never came down, ended at 24mb after your last click. Is that a system memory leak?
    I did noticed this week myself while testing, if I had a list of 2million “rows” of simple strings, the memory goes way up on startup.
    Is the swiftui list drawing all the “rows” and not doing like uikit, reusable rows for rows on display??

  • @crwaha
    @crwaha 3 года назад +2

    I don't think this is workable solution for anything other than very simple cases like in your example. Mainly because it breaks MVVM. If you select a row and push to a new view, using your method, updates to the model will not be reflected in the pushed view. Also you will lose animations and scroll position. There are so many things that break in a proper MVVM design by doing this. I would strongly advise against using this approach.

  • @AhmedMagdy95
    @AhmedMagdy95 4 года назад +1

    Great video as always! However, won't adding id modifier with a new UUID every time the body function is evaluated create a new list even if there is another piece of state that's changed that's not the list state? And if so, will this cause any issues?

    • @shswiftly
      @shswiftly 2 года назад

      no. since the new list will be identical to the last list

  • @sergiovinhal5934
    @sergiovinhal5934 3 года назад

    Thank you Mr Paul Hudson

  • @fredericadda
    @fredericadda 4 года назад +1

    Exceptional! Thanks!
    Love your videos! 🤩

  • @gitakb1980
    @gitakb1980 4 года назад

    Hi Paul, that was an amazing tutorial. Thanks. Could you please help me with this issue. I am building an app where after several steps, on a button press, the user needs to be sent back to the main view. The solutions mentioned in stacktrace, using isdetaillink=false and dismissing each intermediate view is really not a clean code. Is there really no provision of popping to the first view in SwiftUI, like it used to be in objective-C with popToRootViewController?

  • @oglaucio
    @oglaucio 4 года назад +1

    This is brilliant. Thanks for sharing!

  • @himagoshi
    @himagoshi 4 года назад

    On some devices I found this to make the app crash when navigating back to the list from another view (only observed on iPhone 7 & 11, works fine on the rest for me)..

  • @ashtonc1
    @ashtonc1 3 года назад

    Is there a way to do this with a ForEach in a scroll view as opposed to with a List?

  • @trendz4422
    @trendz4422 3 года назад

    please include the tags for time profiler to this video. As this explains small info about how to use instruments to find the delay. I really can't find nice videos that explains instruments options. So it may help someone.

  • @Omeir34
    @Omeir34 4 года назад

    Brilliant Video Paul!

  • @trendz4422
    @trendz4422 3 года назад

    it'd be nice if you can make videos on how to use each instruments tools,.

  • @michoyou7876
    @michoyou7876 4 года назад

    Great explanation!!
    Many thanks.

  • @JoeHinkle11
    @JoeHinkle11 4 года назад

    Awesome explanation. Thanks!

  •  4 года назад

    Welcome back in 2020 🍾

  • @judy8821
    @judy8821 4 года назад

    Thank you, Paul. That makes sense

  • @scottrocha9697
    @scottrocha9697 4 года назад

    Great info! Thanks!

  • @ضدالظلم-د4ح
    @ضدالظلم-د4ح 4 года назад

    Waw that’s so cool
    You saved our carrier
    Thank you so much 😊

  • @tenminutetokyo2643
    @tenminutetokyo2643 4 года назад

    Hit the “Film” setting in FCPX.

  • @syedaffan426
    @syedaffan426 3 года назад

    but i want to do this in swift code in storyboard not in swiftui

  • @abdulzero5841
    @abdulzero5841 4 года назад

    Please do you have a new book on SwiftUI ? If so can you send me link to buy

    • @twostraws
      @twostraws  4 года назад

      I have two books: Hacking with iOS and SwiftUI by Example, both of which cover SwiftUI extensively.

    • @abdulzero5841
      @abdulzero5841 4 года назад

      Link please?

  • @andywong3095
    @andywong3095 4 года назад

    Thank you, sir.

  • @fordee1964
    @fordee1964 4 года назад

    This is a pragmatic fix, but it seems like the wrong thing to be doing. The diff logic is there for a reason. I would guess that this hack won't be needed after SwiftUI matures and some of its bugs are fixed.

  • @aaqibali9458
    @aaqibali9458 4 года назад

    Awsm content

  • @UXSpecialist
    @UXSpecialist 4 года назад

    Why is swift so slow? Obj. C was never this slow

  • @soheilpakgohar6630
    @soheilpakgohar6630 4 года назад

    perfect

  • @balarajan3110
    @balarajan3110 4 года назад

    Great

  • @AngelVazquez-zh3hn
    @AngelVazquez-zh3hn 4 года назад

    🤮🤮🤮🤮