From 1467d2062a91a041661b0dff95f76a1537cbd9fc Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Mon, 17 Jul 2023 15:29:22 -0800 Subject: [PATCH] only store the count of tracers in bookkeeping, not a set of references --- .../SentryProfiledTracerConcurrency.mm | 35 ++++++++----------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/Sources/Sentry/Profiling/SentryProfiledTracerConcurrency.mm b/Sources/Sentry/Profiling/SentryProfiledTracerConcurrency.mm index 70ec1a81271..44a41093f48 100644 --- a/Sources/Sentry/Profiling/SentryProfiledTracerConcurrency.mm +++ b/Sources/Sentry/Profiling/SentryProfiledTracerConcurrency.mm @@ -16,14 +16,14 @@ # endif // SENTRY_HAS_UIKIT /** - * a mapping of profilers to the tracers that started them that are still in-flight and will need to - * query them for their profiling data when they finish. this helps resolve the incongruity between - * the different timeout durations between tracers (500s) and profilers (30s), where a transaction - * may start a profiler that then times out, and then a new transaction starts a new profiler, and - * we must keep the aborted one around until its associated transaction finishes. + * a mapping of profilers to the number of tracers that started them that are still in-flight and + * will need to query them for their profiling data when they finish. this helps resolve the + * incongruity between the different timeout durations between tracers (500s) and profilers (30s), + * where a transaction may start a profiler that then times out, and then a new transaction starts a + * new profiler, and we must keep the aborted one around until its associated transaction finishes. */ static NSMutableDictionary *> *_gProfilersToTracers; + /* number of in-flight tracers */ NSNumber *> *_gProfilersToTracers; /** provided for fast access to a profiler given a tracer */ static NSMutableDictionary @@ -48,21 +48,14 @@ if (_gProfilersToTracers == nil) { _gProfilersToTracers = [NSMutableDictionary *> dictionaryWithObject:[NSMutableSet setWithObject:tracer] - forKey:profilerKey]; + /* number of in-flight tracers */ NSNumber *> + dictionary]; _gTracersToProfilers = [NSMutableDictionary - dictionaryWithObject:profiler - forKey:tracerKey]; - return; - } - - if (_gProfilersToTracers[profilerKey] == nil) { - _gProfilersToTracers[profilerKey] = [NSMutableSet setWithObject:tracer]; - } else { - [_gProfilersToTracers[profilerKey] addObject:tracer]; + dictionary]; } + _gProfilersToTracers[profilerKey] = @(_gProfilersToTracers[profilerKey].unsignedIntValue + 1); _gTracersToProfilers[tracerKey] = profiler; } @@ -85,8 +78,8 @@ const auto profilerKey = profiler.profileId.sentryIdString; [_gTracersToProfilers removeObjectForKey:tracerKey]; - [_gProfilersToTracers[profilerKey] removeObject:tracer]; - if ([_gProfilersToTracers[profilerKey] count] == 0) { + _gProfilersToTracers[profilerKey] = @(_gProfilersToTracers[profilerKey].unsignedIntValue - 1); + if ([_gProfilersToTracers[profilerKey] unsignedIntValue] == 0) { [_gProfilersToTracers removeObjectForKey:profilerKey]; if ([profiler isRunning]) { [profiler stopForReason:SentryProfilerTruncationReasonNormal]; @@ -118,8 +111,8 @@ const auto profilerKey = profiler.profileId.sentryIdString; [_gTracersToProfilers removeObjectForKey:tracerKey]; - [_gProfilersToTracers[profilerKey] removeObject:tracer]; - if ([_gProfilersToTracers[profilerKey] count] == 0) { + _gProfilersToTracers[profilerKey] = @(_gProfilersToTracers[profilerKey].unsignedIntValue - 1); + if ([_gProfilersToTracers[profilerKey] unsignedIntValue] == 0) { [_gProfilersToTracers removeObjectForKey:profilerKey]; if ([profiler isRunning]) { [profiler stopForReason:SentryProfilerTruncationReasonNormal];