1

I noticed that RxSwift slows down the app, I don't know if this is my fault or the framework.

I have binding inside custom class of UICollectionViewCell, which is fired for configuring cell. For example this part of code:

viewModel.observableIsHighlighted.asDriver().drive(onNext: { isHighlighted in
    // do nothing
}).disposed(by: disposeBag)
viewModel.observableIsMarked.asDriver().drive(onNext: { isMarked in
    // do nothing
}).disposed(by: disposeBag)

where observableIsHighlighted, observableIsMarked are just BehaviorRelay<Bool>, takes around 16-20 milliseconds which is unacceptable for UICollectionView of course.

Another part like this:

imageViewTapGestureRecognizer.rx.event.bind(onNext: { _ in
    // do nothing
}).disposed(by: disposeBag)

takes around 12 milliseconds.

Question

Is it something wrong in my approach or binding in RxSwift is not accurate for views like UICollectionView?

Of course, I assume that binding in RxSwift is exactly for things like UICollectionView.

Edit

How am I measuring time?

I use CACurrentMediaTime() multiplied by 1000. I know it's the best way, but methods that are quite simple always take 0 ms, so it suggest that 10-20 ms methods, are should be improved.

Nominalista
  • 4,632
  • 11
  • 43
  • 102
  • I'd love to know the way you measured the delay! – iWheelBuy Jan 07 '18 at 15:20
  • I'm using CACurrentMediaTime(), I know it's not the best way, but I just place code inside instantiating one CACurrentMediaTime() and second CACurrentMediaTime(), then just subtract each other. I guess it's not that bad, because the subtraction between normal parts of code is just 0. Additionally I'm checking that because my UICollectionView stutters. – Nominalista Jan 07 '18 at 15:25
  • I've just measured using CACurrentMediaTime and the delay is 0.06 milliseconds on main. and 3 milliseconds when posted on background and listened on main. – iWheelBuy Jan 07 '18 at 15:48
  • You mean that you measured this parts of code and the delay is just 0.06 milliseconds? I don't know what to think about it... – Nominalista Jan 07 '18 at 16:49
  • I’ll post some code tomorrow – iWheelBuy Jan 07 '18 at 16:50
  • I think I found solution, see my answer. – Nominalista Jan 07 '18 at 17:28

1 Answers1

2

I can't believe, but I updated RxSwift and RxCocoa to 4.1.0 from 4.0 inside my Podfile and now it works perfectly.

Methods from the question take around 0-1 ms now.

Hope this question will help others or maybe anyone would know why I experienced this behavior.

Nominalista
  • 4,632
  • 11
  • 43
  • 102
  • 1
    Very interesting! It is a good approach to upgrade/downgrade the pod version and compare the behavior. – iWheelBuy Jan 07 '18 at 18:13