Bob Lee (who worked on core libraries, the subject of the next chapter) said of Zygote, “It was just so simple! It’s like one API call! The reason we were able to do that was that the memory was copy-on-write.118 So as long as you didn’t touch those memory pages from that initial Zygote process, all that memory would be shared across the whole OS. It was just such a clever, beautiful solution to leverage stuff that was already there.” The system didn’t quite work as intended at first. Bob chased down a problem with the garbage collector: “After one garbage collection, I was like, ‘My app’s
Bob Lee (who worked on core libraries, the subject of the next chapter) said of Zygote, “It was just so simple! It’s like one API call! The reason we were able to do that was that the memory was copy-on-write.118 So as long as you didn’t touch those memory pages from that initial Zygote process, all that memory would be shared across the whole OS. It was just such a clever, beautiful solution to leverage stuff that was already there.” The system didn’t quite work as intended at first. Bob chased down a problem with the garbage collector: “After one garbage collection, I was like, ‘My app’s taking up so much memory again!’ It was because the garbage collector would touch every memory page.” That is, the normal efforts of the runtime would write to pages in memory that needed to stay read-only for the shared-memory approach of Zygote to work. Fadden came in with a fix for this. Each new process would separate the heap from the garbage collector after the Zygote stage, excluding it from the memory that the garbage collector examined. The shared memory portion didn’t even exist in the new app, so it wouldn’t get touched. After this, Bob and Fadden continued to work on Zygote, to figure out which classes119 needed to live in Zygote to get optimal sharing out of all applications. Bob said, “I modified the VM and added some instrumentation, so I could say, like, how long every class initializer is taking, and figure out how much memory each class is allocating, and then an algori...
...more
This highlight has been truncated due to consecutive passage length restrictions.