From b6158d3d155918d9994aebaf39bfc17398fd2f4e Mon Sep 17 00:00:00 2001 From: Alexander Pantiukhov Date: Thu, 7 May 2026 14:58:22 +0200 Subject: [PATCH 1/2] Locally vendored helpers --- packages/core/RNSentry.podspec | 3 +- packages/core/ios/RNSentry+fetchNativeStack.m | 10 ++--- packages/core/ios/RNSentryHexFormatter.h | 40 +++++++++++++++++++ 3 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 packages/core/ios/RNSentryHexFormatter.h diff --git a/packages/core/RNSentry.podspec b/packages/core/RNSentry.podspec index 5054b80451..f786fb7520 100644 --- a/packages/core/RNSentry.podspec +++ b/packages/core/RNSentry.podspec @@ -47,8 +47,7 @@ Pod::Spec.new do |s| s.compiler_flags = other_cflags s.pod_target_xcconfig = { - 'DEFINES_MODULE' => 'YES', - 'HEADER_SEARCH_PATHS' => '$(inherited) "${PODS_ROOT}/Sentry/Sources/Sentry" "${PODS_ROOT}/Sentry/Sources/Sentry/include"' + 'DEFINES_MODULE' => 'YES' } s.dependency 'Sentry', '9.12.1' diff --git a/packages/core/ios/RNSentry+fetchNativeStack.m b/packages/core/ios/RNSentry+fetchNativeStack.m index a3e425b32e..196e726ddf 100644 --- a/packages/core/ios/RNSentry+fetchNativeStack.m +++ b/packages/core/ios/RNSentry+fetchNativeStack.m @@ -1,7 +1,7 @@ #import "RNSentry.h" #import "RNSentryBreadcrumb.h" +#import "RNSentryHexFormatter.h" #import "RNSentryId.h" -#import "SentryFormatter.h" #import @import Sentry; @@ -25,12 +25,12 @@ - (NSDictionary *)fetchNativeStackFramesBy:(NSArray *)instructionsAd SentryBinaryImageInfo *_Nullable image = [[[SentryDependencyContainer sharedInstance] binaryImageCache] imageByAddress:[addr unsignedLongLongValue]]; if (image != nil) { - NSString *imageAddr = sentry_formatHexAddressUInt64([image address]); + NSString *imageAddr = rnsentry_formatHexAddressUInt64([image address]); [imagesAddrToRetrieveDebugMetaImages addObject:imageAddr]; NSDictionary *_Nonnull nativeFrame = @{ @"platform" : @"cocoa", - @"instruction_addr" : sentry_formatHexAddress(addr), + @"instruction_addr" : rnsentry_formatHexAddress(addr), @"package" : [image name], @"image_addr" : imageAddr, @"in_app" : [NSNumber numberWithBool:[appPackageName isEqualToString:[image name]]], @@ -45,7 +45,7 @@ - (NSDictionary *)fetchNativeStackFramesBy:(NSArray *)instructionsAd NSMutableDictionary *_Nonnull symbolicated = nativeFrame.mutableCopy; symbolicated[@"symbol_addr"] - = sentry_formatHexAddressUInt64((uintptr_t)symbolsBuffer.dli_saddr); + = rnsentry_formatHexAddressUInt64((uintptr_t)symbolsBuffer.dli_saddr); symbolicated[@"function"] = [NSString stringWithCString:symbolsBuffer.dli_sname encoding:NSUTF8StringEncoding]; @@ -57,7 +57,7 @@ - (NSDictionary *)fetchNativeStackFramesBy:(NSArray *)instructionsAd } else { [serializedFrames addObject:@{ @"platform" : @"cocoa", - @"instruction_addr" : sentry_formatHexAddress(addr), + @"instruction_addr" : rnsentry_formatHexAddress(addr), }]; } } diff --git a/packages/core/ios/RNSentryHexFormatter.h b/packages/core/ios/RNSentryHexFormatter.h new file mode 100644 index 0000000000..d9e0a84dae --- /dev/null +++ b/packages/core/ios/RNSentryHexFormatter.h @@ -0,0 +1,40 @@ +#import + +// 2 for the "0x" prefix, plus 16 for the hex value, plus 1 for the null terminator. +#define RN_SENTRY_HEX_ADDRESS_LENGTH 19 + +/** + * Formats a 64-bit unsigned integer as a zero-padded hex address string + * (e.g. @c 0x000000010f1a2b3c). + * + * Inlined here so we don't need to reach into sentry-cocoa's private + * @c SentryFormatter.h via @c HEADER_SEARCH_PATHS. Keep behavior identical + * to @c sentry_snprintfHexAddress in sentry-cocoa. + */ +static inline NSString * +rnsentry_snprintfHexAddress(uint64_t value) +{ + char buffer[RN_SENTRY_HEX_ADDRESS_LENGTH]; + snprintf(buffer, RN_SENTRY_HEX_ADDRESS_LENGTH, "0x%016llx", value); + return [NSString stringWithCString:buffer encoding:NSASCIIStringEncoding]; +} + +/** + * Formats an @c NSNumber address as a zero-padded hex string. + * Drop-in replacement for sentry-cocoa's @c sentry_formatHexAddress. + */ +static inline NSString * +rnsentry_formatHexAddress(NSNumber *value) +{ + return rnsentry_snprintfHexAddress([value unsignedLongLongValue]); +} + +/** + * Formats a @c uint64_t address as a zero-padded hex string. + * Drop-in replacement for sentry-cocoa's @c sentry_formatHexAddressUInt64. + */ +static inline NSString * +rnsentry_formatHexAddressUInt64(uint64_t value) +{ + return rnsentry_snprintfHexAddress(value); +} From ecc8f81d1875d667c68820801f325c2b1e615d4a Mon Sep 17 00:00:00 2001 From: Alexander Pantiukhov Date: Thu, 7 May 2026 15:08:13 +0200 Subject: [PATCH 2/2] fixes --- packages/core/ios/RNSentryHexFormatter.h | 28 +++++++++--------------- 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/packages/core/ios/RNSentryHexFormatter.h b/packages/core/ios/RNSentryHexFormatter.h index d9e0a84dae..1290be1a6c 100644 --- a/packages/core/ios/RNSentryHexFormatter.h +++ b/packages/core/ios/RNSentryHexFormatter.h @@ -1,38 +1,30 @@ #import -// 2 for the "0x" prefix, plus 16 for the hex value, plus 1 for the null terminator. +// 2 for the 0x prefix, plus 16 for the hex value, plus 1 for the null terminator #define RN_SENTRY_HEX_ADDRESS_LENGTH 19 -/** - * Formats a 64-bit unsigned integer as a zero-padded hex address string - * (e.g. @c 0x000000010f1a2b3c). - * - * Inlined here so we don't need to reach into sentry-cocoa's private - * @c SentryFormatter.h via @c HEADER_SEARCH_PATHS. Keep behavior identical - * to @c sentry_snprintfHexAddress in sentry-cocoa. - */ static inline NSString * rnsentry_snprintfHexAddress(uint64_t value) { char buffer[RN_SENTRY_HEX_ADDRESS_LENGTH]; snprintf(buffer, RN_SENTRY_HEX_ADDRESS_LENGTH, "0x%016llx", value); - return [NSString stringWithCString:buffer encoding:NSASCIIStringEncoding]; + NSString *nsString = [NSString stringWithCString:buffer encoding:NSASCIIStringEncoding]; + return nsString; } -/** - * Formats an @c NSNumber address as a zero-padded hex string. - * Drop-in replacement for sentry-cocoa's @c sentry_formatHexAddress. - */ static inline NSString * rnsentry_formatHexAddress(NSNumber *value) { + /* + * We observed a 41% speedup by using snprintf vs +[NSString stringWithFormat:]. In a trial + * using a profile, we observed the +[NSString stringWithFormat:] using 282ms of CPU time, vs + * 164ms of CPU time for snprintf. There is also an assumed space improvement due to not needing + * to allocate as many instances of NSString, like for the format string literal, instead only + * using stack-bound C strings. + */ return rnsentry_snprintfHexAddress([value unsignedLongLongValue]); } -/** - * Formats a @c uint64_t address as a zero-padded hex string. - * Drop-in replacement for sentry-cocoa's @c sentry_formatHexAddressUInt64. - */ static inline NSString * rnsentry_formatHexAddressUInt64(uint64_t value) {