sentry-cocoa icon indicating copy to clipboard operation
sentry-cocoa copied to clipboard

Check `@synchronized` usages

Open armcknight opened this issue 3 years ago • 1 comments

@synchronized is the most heavyweight synchronization mechanism of those available, and we use it in 166 places. Try running our tests through Instruments to see what kind of performance penalty we're incurring by using it and if we deem it necessary in any situation, consider using NSLock or pthread_mutex (which could be used via C++'s std::mutex wrapper, which provides the convenient std::lock_guard).

Things to keep in mind when removing @synchronized:

  • it sets up an implicit recursive lock; if we need recursion, we'd have to use NSRecursiveLock or std::recursive_mutex
  • it sets up an implicit exception handler; if we rely on this mechanism, we'd have to hand code it ourself

armcknight avatar Sep 16 '22 02:09 armcknight

Based on your description, I believe that even though '@syncronized' is the heaviest, it's also the simplest to use. Is that right?

Maybe we should only consider updating those places that are called multiple times per second.

brustolin avatar Sep 16 '22 07:09 brustolin