macOS + rustlib.a + Xcode test == very slow "symbolication"

I have a macOS swift app that's using my rustlib.a file.

Generally app works well, but when I run Xcode tests I often get 2+ minute delays when Xcode needs to create a symbolication record to go with a test report. For example when a test fails or a performance test finishes I see the delay.

This problem is related to including the rustlib.a file... as soon as I remove that it goes away. I'm building the lib with cargo build. Is there something that I can do to avoid this?

Here is what the stack trace looks like:

Thread 1 Queue : com.apple.main-thread (serial)
#0	0x00007fff68ae86a2 in __open ()
#1	0x0000000102ca2a34 in CSCppFileMemory::CSCppFileMemory(char const*, TRange<Pointer64>, unsigned int) ()
#2	0x0000000102ca01cb in new_partial_file_memory(char const*, unsigned long long, unsigned int, unsigned long long (CSCppFileMemory*) block_pointer) ()
#3	0x0000000102ca14eb in iterate_symbol_owners_from_archive(char const*, unsigned long long, unsigned int, CSCppArchitecture const&, char const*, bool, void (CSCppSymbolOwner*) block_pointer) ()
#4	0x0000000102ca04ef in iterate_symbol_owners_from_memory(CSCppMemory*, char const*, unsigned int, unsigned long long, unsigned int, CSCppArchitecture const&, char const*, bool, void (CSCppSymbolOwner*) block_pointer) ()
#5	0x0000000102ca0d46 in iterate_symbol_owners_from_path(char const*, bool, unsigned int, CSCppArchitecture const&, bool, void (CSCppSymbolOwner*) block_pointer) ()
#6	0x0000000102c907bf in CSSymbolicatorCreateWithPathArchitectureFlagsAndNotification ()
#7	0x0000000102c89133 in void extract_debug_maps_from_header<SizeAndEndianness<Pointer64, LittleEndian> >(TExtendedMachOHeader<SizeAndEndianness<Pointer64, LittleEndian> >&, TRawSymbolOwnerData<SizeAndEndianness<Pointer64, LittleEndian>::SIZE>&, TNList<SizeAndEndianness<Pointer64, LittleEndian> > const*, unsigned int, TRange<SizeAndEndianness<Pointer64, LittleEndian>::SIZE>) ()
#8	0x0000000102cc3be0 in TRawSymbolOwnerData<SizeAndEndianness<Pointer64, LittleEndian>::SIZE>* create_traw_symbol_owner_data_arch_specific<SizeAndEndianness<Pointer64, LittleEndian> >(CSCppSymbolOwner*, CSCppDsymData*) ()
#9	0x0000000102c7e69a in CSCppSymbolOwnerData* create_symbol_owner_data_arch_specific<SizeAndEndianness<Pointer64, LittleEndian> >(CSCppSymbolOwner*, CSCppDsymData*) ()
#10	0x0000000102c7e16d in create_symbol_owner_data2(CSCppSymbolOwner*, CSCppDsymData*) ()
#11	0x0000000102c7dd2c in CSCppSymbolOwnerCache::create_symbol_owner_data(CSCppSymbolOwner*, CSCppDsymData*) ()
#12	0x0000000102c7d6af in CSCppSymbolOwnerCache::data_for_symbol_owner(CSCppSymbolOwner*) ()
#13	0x0000000102c7d656 in CSCppSymbolOwner::data() ()
#14	0x0000000102c83ff3 in CSSymbolicatorGetSymbolWithAddressAtTime ()
#15	0x0000000102a769e1 in +[XCSymbolicationRecord symbolicationRecordForAddress:] ()
#16	0x0000000102a2798b in -[XCTestCase _symbolicationRecordForTestCodeInAddressStack:] ()
#17	0x0000000102a293ac in -[XCTestCase reportMetric:reportFailures:] ()
#18	0x0000000102a2b9db in -[XCTestCase measureMetrics:automaticallyStartMeasuring:forBlock:] ()
#19	0x0000000102a25a9b in -[XCTestCase measureBlock:] ()
#20	0x0000000105002c77 in BikeServiceTests.testPerformance() at /Users/jessegrosjean/Documents/github/Bike/clients/bike.swift/Common Tests/BikeServiceTests.swift:29
...

I was able to greatly improve this by changing from a static lib to a dylib (cdylib) embedded in my app.

  1. For both cases I've been using https://crates.io/crates/cargo-xcode to present the lib to my Swift app.
  2. For the dylib case I also needed to (and wow took me a while to figure this out) change the dylib id to use @executable_path using install_name_tool. Otherwise everything would work, until I deleted Xcode build artifacts. So for my case I added this to b build script:
install_name_tool -id @executable_path/../Frameworks/libbike_service.dylib "${CARGO_XCODE_PRODUCTS_DIR}/libbike_service.dylib"

I'm also happy and a bit surprised to find that this change has significantly decreased my .app size.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.