1
votes

I have an x86_64 macOS app that according to Activity Monitor, it uses between 35 to 50MB of memory with an Intel MacBook Pro. When I run the same app in an M1 MacBook Pro with Rosetta, it shows 2.5 to 3x more memory in Activity Monitor.

I then updated the app in my M1 to both x86_64 and arm64, and run it again. In the Intel MacBook Pro it uses 40 to 60MB in Activity Monitor. In the M1, Xcode still shows the 3x increase in Memory Report and Activity Monitor.

In the M1, from Memory Report I clicked Profile in Instruments and it shows the heaviest stack trace is in system libraries, specifically this one:

46 AppKit 183.46 MB +[NSBundle(NSNibLoading) loadNibNamed:owner:]

See the image and the call tree all the way down to mmap:

enter image description here

However, when I try to profile the app again in my M1 but directly from Instruments > Allocations, it shows the regular 35-50MB memory usage, nothing more. [NSBundle(NSNibLoading) loadNibNamed:owner:] is not taking all the memory as above. Here is an image:

enter image description here

The only graphics the app has are a couple of storyboards with some custom Core Graphics code for custom drawings. I'm on Big Sur 11.2 and Xcode 12.4.

My understanding of memory usage using Instruments is basic, so my questions are:

  1. What could be happening here with the different memory usage between M1 vs Intel, and between Instruments and Instruments running from Memory Report?
  2. Why is all the memory going to this NSBundle(NSNibLoading) loadNibNamed:owner:]?
  3. How can I reduce the memory usage for the M1?

Thanks for any help!

1
Have you tried comparing how builtin apps fare under roseta? It might just be that rosetta apps have a memory overhead in general - Alexander
Thanks. My app is running native (arm64) in the M1. Built in apps like Finder, Calculator, etc. also run native and use kind the same memory with the Intel, except Notes and Calendar; this last one shows almost double in the M1. I have other third party apps in the M1 running in Rosetta that indeed run with 2x more memory. I have one running native and has the same memory with the Intel. I could understand the Rosetta translation is causing the memory overhead, but my app is arm64. I would like to know why and if that could be fixed. - RobMoj

1 Answers

0
votes

If you want to see how much memory your app is using, look at the Persistent Bytes column for the All Heap Allocations category in the Allocations instrument. Note that this category does not include texture memory.

To make it easier to find the code that allocates the most memory, click the Call Tree button at the bottom of the Instruments window and select the Invert Call Tree and Hide System Libraries checkboxes. The following tutorial provides a detailed explanation on using Instruments to measure memory usage:

Measuring Your App's Memory Usage with Instruments