- Optimization Rules
- Optimization Tricks
- Memory Usage and the Garbage Collector
- Perceived Performance
Back in the 19th century, an Italian economist named Vilfredo Pareto noticed something about the distribution of wealth in many countries: About 80% of the wealth was controlled by about 20% of the people. Pareto's principle came to be known as the 80:20 rule, and since then, the basic idea has been applied to all sorts of other fields, including business sales, project management, and computer science. What's that? Computer science, you say? Yup. The computer science version of this rule (or one of them, anyway) says that 80% of your program's time is spent in 20% of your code. The good news here is the HotSpot VM: It finds that 20% (the "hot" code) and compiles it into optimized machine code. However, HotSpot doesn't do everything. It doesn't perform every possible optimization, and it won't rewrite your code to use more efficient algorithms. In this chapter, we talk about how to find that 20%, what optimizations HotSpot does and doesn't do, and memory usage and the garbage collector. What's not in this chapter is size optimization (making classes as small as possible). Obfuscators take care of code size (which we talk about in , "Game Design and the Last 10%"), but for larger games, the bulk is really in resources such as maps, images, and 3D models, not in the code.