Slashdot Mirror


How Snow Leopard Cut ObjC Launch Time In Half

MBCook writes "Greg Parker has an excellent technical article on his blog about the changes to the dynamic linker (dyld) for Objective-C that Snow Leopard uses to cut launch time in half and cut about 1/2 MB of memory per application. 'In theory, a shared library could be different every time your program is run. In practice, you get the same version of the shared libraries almost every time you run, and so does every other process on the system. The system takes advantage of this by building the dyld shared cache. The shared cache contains a copy of many system libraries, with most of dyld's linking and loading work done in advance. Every process can then share that shared cache, saving memory and launch time.' He also has a post on the new thread-local garbage collection that Snow Leopard uses for Objective-C."

4 of 158 comments (clear)

  1. Re:enough fucking by Anonymous Coward · · Score: 5, Funny

    You've had enough of fucking, and would like more Snow Leopard stories? Each to his own, I guess.

  2. Re:I've heard that before.... by BorgDrone · · Score: 5, Informative

    Did you even read the article ? Suppose not... this is slashdot after all.

    The article states that prebinding (similar to prelink) was used in previous versions of OS X and has been replaced by a much faster shared cache.

  3. dyld by DoofusOfDeath · · Score: 5, Funny

    dyld - noun. A reminder that regardless of age, you'll always have an adolescent sense of humor.

  4. Re:I've heard that before.... by plsuh · · Score: 5, Informative

    Moderators, please mod the parent down -- it completely misses the point.

    Objective-C selector uniquing caching is NOT the same as Windows Superfetch.

    Objective-C uses a two-phase dispatch for method calls. When you see a call in the Objective-C source code that looks like:

    [myObject init];

    the dispatch system:

    1. Looks up the function pointer for the method "init" in a table.
    2. Calls the "init" function via the function pointer.

    The problem arises in the method dispatch table when you have multiple methods named "init" -- which is very common. When an application is loaded the dynamic loader ("dyld") needs to separately identify all of the methods named "init" (and any other methods with conflicting names) that apply to different classes. This is done by "tagging" each method in the dispatch table, a process called selector uniquing.

    Now, this has to be not only for the application binary itself, but also for any Objective-C classes in shared libraries that are loaded. Almost all apps on Mac OS X load the libobjc.dylib library, which is cached to improve performance. As a part of the caching process, Snow Leopard now does the selector uniquing only once, and then stores the uniqued selectors in the cache. Thus, any application that links against libobjc.dylib (or any other library that is in the cache) only has to unique its own selectors, not those of the library as well. This significantly reduces the amount of overhead for launching an application compared to previous versions of Mac OS X.

    This process does not attempt to retain application binary code in memory in the face of page-outs as Superfetch does. Selector uniquing caching speeds application launch times by reducing the amount of computation that has to happen at launch, not by pre-loading the application's binary.

    Thread-local garbage collection is NOT the same as Windows Superfetch.

    Thread-local garbage collection is a third phase of garbage collection added on top of the Objective-C 2.0 garbage collection system, which speeds up the garbage collection system even further. By concentrating GC to what has occurred in a single thread, the GC system can delay and reduce the cost of a slow global sweep even beyond the generational GC algorithm.

    Windows Superfetch is a response to poorly written software.

    To quote from the Wikipedia article:

    The intent is to improve performance in situations where running an anti-virus scan or back-up utility would result in otherwise recently-used information being paged out to disk, or disposed from in-memory caches, resulting in lengthy delays when a user comes back to their computer after a period of non-use.

    In my opinion as an experienced application developer the user should never run into the problem that Superfetch attempts to solve. Anti-malware scans or backups are generally limited by I/O transfer rates, not by CPU. In such situations, using lots of memory to pre-load data makes no sense. It is relatively easy to write a two-buffer, threaded, streaming system for situations that are constrained by disk transfer rates without consuming scads of memory.

    In the bigger picture, Superfetch attempts to learn the times of day when apps are used and pre-loads their binaries. This is a nice concept, but I have serious doubts as to how useful it really is. The penalty for guessing wrong is fairly high, and users are more tolerant of consistent small slowdowns than they are of occasional long hangs (see the Mac literature on the spinning beach ball).

    Mac OS X is less likely to need such anti-malware scans in the first place as the application binaries are now digitally signed by the developer. Any malware that attempts to insert itself into applications will run into problems. This is not to say that the Mac is immune -- I can think of a number of holes that could be exploited (such as the fact that unsigned binaries w