Performance problem


I built an application that is currently running on another UNIX protform and OS 9. The port itself went relatively ok, everything was as expected, but it turns out that on the same hardware OS X run 10 times slower than OS 9. Comparing to UNIX the situation was even worse, even tought the box is an old 128MB 233MHz PPC running AIX.

In order to isolate the problem I made a small program that repitedly performs malloc () and free(), this one took on OS X 20 times more than OS-9 and 30 t imes more than on AIX.

Profiler shows that 1/3 of the time was waisted in a function called in _mach_msg_overwrite ( libc) but I don't know how did I get there. free() itself took less than 6% of the time , and malloc another 1.8%. So I don't know what was my program doing for more than 90% of the time.

Did any of you have a similar problem? The tests I made are from are on 10.0.4, but we have the same problem on 10.1 ( no measures there yet ).

My machine is a 256MB PPC G4 at 733 MHz




My first question is to ask whether you have any of the malloc debugging settings turned on. There are several environment variables you can set which enable debugging of malloc-related features; to see if any are set, run

env |grep Malloc
If you see any set, that would probably slow it down; the variables which can be used are:

- MallocGuardEdges to add 2 guard pages for each large block
- MallocDoNotProtectPrelude to disable protection (when previous flag set)
- MallocDoNotProtectPostlude to disable protection (when previous flag set)
- MallocStackLogging to record all stacks. Tools like leaks can then be applied
- MallocStackLoggingNoCompact to record all stacks. Needed for malloc_history
- MallocScribble to detect writing on free blocks: 0x55 is written upon free
- MallocCheckHeapStart <n> to check the heap from time to time after <n> operations
- MallocHelp - this help!