About the Author xv
Introduction xvii
Â
Chapter 1: CPU: Principles 1
A Simple Example 2
The Power of Hybrids 10
Trends 11
Cost of Operations 12
Computational Complexity 14
Summary 16
Â
Chapter 2: CPU: Measurement and Tools 17
Command-Line Tools 18
Xcode Gauges 22
Instruments 22
Internal Measurement 35
Dtrace 38
Optimization Beyond the Call of Duty 38
Summary 39
Â
Chapter 3: CPU: Pitfalls and Techniques 41
Representation 41
Objects 48
Messaging 64
Methods 71
Multicore 72
Mature Optimization 75
Â
Chapter 4: CPU Example: XML Parsing 79
An HTML Scanner 80
Mapping Callbacks to Messages 83
Objects 85
Objects, Cheaply 87
Evaluation 90
Tune-Ups 93
Optimizing the Whole Widget: MAX 94
MAX Implementation 96
Summary 97
Â
Chapter 5: Memory: Principles 99
The Memory Hierarchy 99
Mach Virtual Memory 105
Heap and Stack 106
Resource Management 113
Summary 117
Â
Chapter 6: Memory: Measurement and Tools 119
Xcode Gauges 119
Command-Line Tools 120
Internal Measurement 125
Memory Instruments 126
Summary 136
Â
Chapter 7: Memory: Pitfalls and Techniques 137
Reference Counting 137
Foundation Objects vs. Primitives 141
Smaller Structures 142
Memory and Concurrency 146
Architectural Considerations 147
Temporary Allocations and Object Caching 151
NSCache and libcache 153
Memory-Mapped Files 153
madvise 156
iOS Considerations 157
Optimizing ARC 157
Summary 160
Â
Chapter 8: Memory Example: FilterStreams 161
Unix Pipes and Filters 161
Object-Oriented Filters 163
DescriptionStream 164
Stream Hierarchy 170
Summary 171
Â
Chapter 9: Swift 173
Swift Performance: Claims 173
Assessing Swift Performance 177
Larger Examples 188
Compile Times 191
Optimizer-Oriented Programming 195
A Sufficiently Smart Compiler 197
Summary 204
Â
Chapter 10: I/O: Principles 205
Hardware 205
Operating System 208
Summary 214
Â
Chapter 11: I/O: Measurement and Tools 215
Negative Space: top and time 216
Summary Information: iostat and netstat 217
Instruments 218
Detailed Tracing: fs_usage 221
Summary 224
Â
Chapter 12: I/O: Pitfalls and Techniques 225
Pushing Bytes with NSData 225
Unixy I/O 230
Network I/O 232
Serialization 242
CoreData 253
SQLite 261
Event Posting 264
Segregated Stores 265
Summary 266
Â
Chapter 13: I/O: Examples 267
iPhone Game Dictionary 267
Fun with Property Lists 271
Comma-Separated Values 282
Public Transport Schedule Data 283
Faster CSV Parsing 288
Summary 293
Â
Chapter 14: Graphics and UI: Principles 295
Responsiveness 295
Software and APIs 296
Quartz and the PostScript Imaging Model 299
OpenGL 300
Metal 301
Graphics Hardware and Acceleration 301
From Quartz Extreme to Core Animation 305
Summary 308
Â
Chapter 15: Graphics and UI: Measurement and Tools 309
CPU Profiling with Instruments 310
Quartz Debug 311
Core Animation Instrument 312
What Am I Measuring? 318
Summary 323
Â
Chapter 16: Graphics and UI: Pitfalls and Techniques 325
Pitfalls 325
Techniques 326
Too Much Communication Slows Down Installation 327
Overwhelming an iPhone 330
It’s Just an Illusion 332
Line Drawing on iPhone 338
Summary 341
Â
Chapter 17: Graphics and UI: Examples 343
Beautiful Weather App 343
Wunderlist 3 350
Summary 357
Â
Index 359