Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance speed of KVO and NSNotifications?

Should I be afraid of using Key-Value Observations (KVO) and NSNotifications? I'm beginning to use them in my app, but I'm a little unfamiliar with the concept of something that could possibly be triggering an appwide call or automatically doing stuff, and a little afraid of the performance hit that such overhead could bring.

Are my concerns unfounded? Should I use them just like any other method call? They seem very convenient and fill a lot of gaps, so I'd like to use them if possible. Note: I am programming primarily for iOS devices, so performance is always a concern for me.

like image 776
David Liu Avatar asked Aug 09 '10 19:08

David Liu


1 Answers

Both Key-Value observers and NSNotifications are pretty light-weight and were just fine on desktop machines that had less power than an iPad. That said, performance questions of the "should I?" type can only be answered by profiling. I think you'll find most folks would recommend, abscent any specific performance requirements that require up-front design, you write the app in the way that makes most sense architecturally and is most efficient for development. Then profile, profile, profile. If you find that KVO or notifications are taking a significant amount of your apps time (I doubt that will be the case), then consider more performant solutions (though there aren't many).

like image 141
Barry Wark Avatar answered Nov 17 '22 13:11

Barry Wark