sergdort / CleanArchitectureRxSwift

Example of Clean Architecture of iOS app using RxSwift

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem with performance in case of dequeueReusableCell

karpov3 opened this issue · comments

Hi @sergdort , thank you for your interesting work. We got a lot of inspiring things from that.

I would like to share one of the problem that we are trying to resolve in process of adopt Input, Output and transform method between View and ViewModel.

In our project we use RxSwift + MVVM + Coordinator. ViewModel of Cell in our UICollectionView has to implement some work for UI of cell. So when UICollectionViewDataSource calls dequeueReusableCell every time Cell calls method transform and create new output from ViewModel. It requires a little bit of time for UI so it’s visible on scroll. In our first approach, Cell subscribed on event of already created VIewModel and it worked fine (but this solution was less functional). Now we call every time transform method and it blocks UI on scroll because ViewModel should be recreated every time.

Did you ever think about similar situation or do you have some ideas how it can be resolved?
Thank you

Hi, @karpov3

This is an interesting problem. TBH I've never encountered any performance issues with Rx. I wonder is it establishing transformations takes so much time (and it's really surprising, as it's just allocation of some operator classes)
Are you sure that you're not doing any heavy computations on subscription?

@sergdort Yes, I have pretty complex cell, because inside of it I have another CollectionView. Every time when cell is reused, in transform method I initialize viewmodels for nested CollectionView. It takes time. Temporary, to resolve the issue, I removed from transform Driver that initialize viewmodels for nested collectionView and declared it as a constant.

Yeah, I would not use this solution for `UI{Table/Collection}ViewCell. And have them as a constant property on a VM