12 ms·
> Looks like the performance bottlenecks are from deep recursion. That's probably something that might be code-around-able. UIKit doesn't have as deep a recursi
by ericlewis 4y ago
> Looks like the performance bottlenecks are from deep recursion. That's probably something that might be code-around-able. UIKit doesn't have as deep a recursion, but it has many other default behaviors that can result in slow performance, and a lot of my "tuning" is about finding these, and determining more optimal code solutions (like redrawing, as opposed to triggering new layouts, etc.; which isn't as easy as you might think. Sometimes, setting a variable in an instance can trigger a new layout).
SwiftUI is designed in a way where deep recursion is a "happens once" problem. There is a lot more compiler trickery going on than people realize, and SwiftUI actually has a very good idea of the entire hierarchy and attempts to efficiently work on said hierarchy -- the cleverness of their algos may not always be clever enough however.
> I think that the idea of "code once, deploy everywhere," which SwiftUI promises, is pretty much a smoke seller's[0] dream. It's a classic. C was supposed to do that. Java was supposed to do that, etc.
this is a very common misconception I see passed around a lot, SwiftUI is more like react-native "learn once, write anywhere". You can have universal codebases with SUI but that is more the exception than the rule ime.
> So, even if I was using SwiftUI, I'd still release an iOS version, a Watch version, a Mac version, etc., with specializations for each.
this is what most people do, you can have a common logical core and entirely different SUI frontends.
> If I write AppKit/UIKit/WatchKit, it really should be MVC, and not just MVC, but NSObject-based MVC. I know, I know, "But what about MVVM?". I feel that MVVM is an excellent model, but that it is not how these frameworks were designed, so they need to be sort of "kludged" to support it. I work in MVC, because they are totally meant for that model.
this is a strange addition to the entire subject. you can write things as MVC with SUI, that is essentially what observable objects do. You can also easily bend them into MVVM. I don't use either approach, and instead go the Flux route.
> I'm looking forward to seeing how SwiftUI evolves, but I have yet to be convinced that it is a viable model for me to write shipping software.
I have had apps featured by Apple that are SUI only, I have shipped SUI only apps to literally 300,000 users.. and I have also shipped UIKit apps to millions. A few things I have noticed is:
1. We have far less crashes than any UIKit app we have ever shipped. 99.8% crash free range with my current work.
2. Developer velocity is insane, between two people we have no issue with shipping everything that was asked for and more which leads me to...
3. It has lead to far more collaboration with design teams since we can jam on design together!
I chose react-native for similar reasons when I worked at Chime. But the moment Apple dropped their own.. I knew it was the only way forward.
Edit: also wanna add that many things in SwiftUI are simply bridged to UIKit or AppKit anyway. Maybe that explains some performance issues. But from literally all of my experience it just has been people with a poor understanding of efficient declarative UI development. A problem that affects all declarative UI dev.
- ChrisMarshallNY 4y ago> this is a strange addition to the entire subject. you can write things as MVC with SUI That's basically what I was saying. SUI is a lot more flexible, than the "classic" SDKs. They require MVC, but SUI lets you use whatever model you want. Thanks for the experienced contribution! Still not confident that SUI would give me the app I'm developing now. It's a fairly ambitious one. Lots of moving parts. But I am often wrong, so I'll definitely be watching this space.
- ericlewis 4y agowell, no. you can use MVVM with UIKit.. or VIPER.. or CLEAN. I have seen them all. And on the note of the app you are developing now.. you would be surprised! I don't often plug my own apps.. but if you look up snap web studios in the app store both of those apps are purely SwiftUI with maybe one or two UIKit bridges for the hacker news app. Eggy is ambitious from a UX perspective, and the HN app is just straight-up impressive and demonstrates that you can make complex and very fast SUI apps. edit: also, not sure if you were aware -- but you can use observable objects & such with UIKit :P
- ChrisMarshallNY 4y ago> you can use MVVM But they are still a deviation from the model the SDK was designed for. The original Apple SDKs are totally bog-standard MVC models. If I try anything other than that, the code complexity increases a lot (especially with VIPER). I think that a lot of these models were developed to allow projects that were really supposed to be doable by one experienced person, to be broken into something for a team of relatively inexperienced people. That's not necessarily a bad thing; but it's not how I work. I like keeping things simple; even though it never ends up simple (See "Programmer's Credo," above). > but you can use observable objects & such with UIKit Yeah, but it's not really "native" support, like AppKit. SwiftUI has it baked into its DNA.
- ericlewis 4y agoit is a really well established pattern now a day tho and most iOS eng i come across know how to work with it. also totally agree on keeping it simple, but I spend about 6 months designing a codebase we could bring anyone up to speed on and it has worked!