iOS和macOS性能优化:Cocoa、Cocoa Touch、Objective-C和Swift
作者:(德)马塞尔-韦伊尔
出版社:电子工业出版社
出版时间:2018-06-01
ISBN:9787121338144
定价:¥99.00
1 CPU:原理 ...................................................................................................................... 1
一个简单的例子 ......................................................................................................................... 2
(微)基准的危险 ............................................................................................................. 3
更多整数求和的方式 ....................................................................................................... 4
Swift.................................................................................................................................. 5
其他语言 ........................................................................................................................... 7
混编的力量 ................................................................................................................................ 9
趋势 .......................................................................................................................................... 10
操作成本 .................................................................................................................................. 12
复杂度计算 ............................................................................................................................... 14
总结 .......................................................................................................................................... 16
2 CPU:测量和工具 ......................................................................................................... 17
命令行工具 ............................................................................................................................... 18
top ................................................................................................................................. 18
time ............................................................................................................................... 19
sample ........................................................................................................................... 19
Xcode 测量工具 ........................................................................................................................ 22
Instruments................................................................................................................................ 23
设置和数据收集 ............................................................................................................. 24
性能分析选项 ................................................................................................................. 25
基本分析 ......................................................................................................................... 27
源代码 ............................................................................................................................. 29
数据挖掘I:Focus ......................................................................................................... 31
数据挖掘II:Pruning ..................................................................................................... 34
内部测量 .................................................................................................................................. 35
测试 ................................................................................................................................ 36
dtrace(dynamic tracing,动态跟踪) .................................................................................... 37
职责之外的优化 ....................................................................................................................... 38
总结 .......................................................................................................................................... 39
3 CPU:陷阱和优化技巧 .................................................................................................. 41
数据表示 .................................................................................................................................. 41
基本类型 ......................................................................................................................... 42
字符串 ............................................................................................................................. 45
对象 .......................................................................................................................................... 47
存取器 ............................................................................................................................. 48
公共访问(Public Access) ........................................................................................... 51
对象创建和缓存 ............................................................................................................. 52
可变性和缓存 ................................................................................................................. 53
惰性求值 ......................................................................................................................... 55
缓存注意事项 ................................................................................................................. 55
陷阱:通用(中级)表示 ............................................................................................. 57
数组和批处理 ................................................................................................................. 58
字典 ................................................................................................................................ 60
消息传递 .................................................................................................................................. 63
IMP 缓存 ......................................................................................................................... 65
转发 ................................................................................................................................ 67
均匀性和优化 ................................................................................................................. 69
方法 .......................................................................................................................................... 70
陷阱:CoreFoundation ................................................................................................... 70
多核 .......................................................................................................................................... 71
线程(Thread) .............................................................................................................. 72
工作队列 ......................................................................................................................... 73
有节制地优化 ........................................................................................................................... 74
4 CPU 实战:XML 解析 ................................................................................................... 77
HTML 扫描器 ........................................................................................................................... 78
将回调映射为消息.................................................................................................................... 81
对象 .......................................................................................................................................... 83
对象的高效性能 ....................................................................................................................... 85
性能评估 .................................................................................................................................. 88
调整 .......................................................................................................................................... 91
优化整个组件:MAX .............................................................................................................. 92
MAX 实现 ................................................................................................................................ 94
总结 .......................................................................................................................................... 95
5 内存:原理 .................................................................................................................... 97
内存层次结构 ........................................................................................................................... 97
Mach 虚拟内存 ....................................................................................................................... 103
堆和栈 .................................................................................................................................... 104
栈分配 ........................................................................................................................... 106
使用malloc()进行堆分配 ....................................................................................... 108
资源管理 ................................................................................................................................ 111
垃圾回收 ....................................................................................................................... 111
Foundation 对象所有权 ................................................................................................ 112
跟踪垃圾回收 ............................................................................................................... 113
自动引用计数(Automatic Reference Counting) ...................................................... 114
过程式资源回收 ........................................................................................................... 115
总结 ........................................................................................................................................ 115
6 内存:测量与工具 ....................................................................................................... 117
Xcode 计量表 .......................................................................................................................... 117
命令行工具 ............................................................................................................................. 118
top ............................................................................................................................... 118
heap .............................................................................................................................. 120
leaks 及malloc_debug ......................................................................................... 122
代码内进行内存测量 .............................................................................................................. 123
内存监测工具 ......................................................................................................................... 124
Leaks .............................................................................................................................. 124
Allocations ..................................................................................................................... 125
VM Tracker .................................................................................................................... 132
计数器与性能监测事件 ............................................................................................... 133
总结 ........................................................................................................................................ 134
7 内存:陷阱和优化技巧 ................................................................................................ 137
引用计数 ................................................................................................................................ 137
避免内存泄漏 ............................................................................................................... 139
Foundation 对象和基本类型对比 .......................................................................................... 141
更小的结构 ............................................................................................................................. 143
千禧危机 ....................................................................................................................... 145
压缩 ............................................................................................................................... 145
可清除内存 ................................................................................................................... 146
内存与并发 ............................................................................................................................. 146
架构注意事项 ......................................................................................................................... 147
临时分配与对象缓存 .............................................................................................................. 152
NSCache 与libcache ............................................................................................................... 153
内存映射文件 ......................................................................................................................... 154
madvise ................................................................................................................................ 157
iOS 注意事项 .......................................................................................................................... 158
ARC 优化 ............................................................................................................................... 158
总结 ........................................................................................................................................ 161
8 内存管理实战:FilterStream 架构 ............................................................................... 163
UNIX 管道及过滤器 ............................................................................................................... 163
面向对象的过滤器.................................................................................................................. 165
DescriptionStream .................................................................................................................... 166
消除description 中的无限递归 ........................................................................... 170
数据流层次结构 ..................................................................................................................... 172
总结 ........................................................................................................................................ 173
9 Swift ............................................................................................................................ 175
Apple 所声称的Swift 性能 .................................................................................................... 175
语言特性 ....................................................................................................................... 177
基准代码 ....................................................................................................................... 179
Swift 性能评估 ........................................................................................................................ 180
基本性能特征 ............................................................................................................... 180
集合 ............................................................................................................................... 181
更进一步 ................................................................................................................................ 190
Nginx HTTP 解析器 ..................................................................................................... 190
Freddy JSON 解析器 .................................................................................................... 191
图片处理 ....................................................................................................................... 191
观察 ............................................................................................................................... 192
编译时间 ................................................................................................................................ 193
类型推断 ....................................................................................................................... 193
泛型特化 ....................................................................................................................... 195
全模块优化 ................................................................................................................... 197
控制编译时间 ............................................................................................................... 197
面向优化器编程 ..................................................................................................................... 198
一个足够智能的编译器 .......................................................................................................... 199
优化编译器之死 ........................................................................................................... 201
实用建议 ....................................................................................................................... 203
备用方案 ....................................................................................................................... 204
总结 ........................................................................................................................................ 207
10 I/O:原理 .................................................................................................................. 209
硬件 ........................................................................................................................................ 209
硬盘驱动器 ................................................................................................................... 209
固态硬盘 ....................................................................................................................... 211
网络 ............................................................................................................................... 212
操作系统 ................................................................................................................................ 212
抽象概念:字节流 ....................................................................................................... 212
文件I/O ......................................................................................................................... 214
网络栈 ........................................................................................................................... 218
总结 ........................................................................................................................................ 218
11 I/O:测量与工具 ........................................................................................................ 221
负形空间:top 与time ....................................................................................................... 222
信息概览:iostat 和netstat......................................................................................... 223
Instruments.............................................................................................................................. 224
详细追踪:fs_usage .......................................................................................................... 228
总结 ........................................................................................................................................ 231
12 I/O:陷阱和优化技巧 ................................................................................................ 233
将字节封装为NSData ............................................................................................................ 233
内存映射异常 ............................................................................................................... 235
如何分块 ....................................................................................................................... 237
UNIXy I/O ............................................................................................................................... 238
网络I/O .................................................................................................................................. 240
堆叠传输 ....................................................................................................................... 241
限制请求 ....................................................................................................................... 243
数据处理 ....................................................................................................................... 244
异步I/O ......................................................................................................................... 245
HTTP 服务 .................................................................................................................... 246
序列化 .................................................................................................................................... 250
内存转储 ....................................................................................................................... 251
一个简单的XML 格式 ................................................................................................. 252
属性列表 ....................................................................................................................... 254
归档 ............................................................................................................................... 256
序列化总结 ................................................................................................................... 258
CoreData ................................................................................................................................. 260
批量创建和更新 ........................................................................................................... 261
Fetch 和Fault 技术 ....................................................................................................... 263
对象交互 ....................................................................................................................... 266
子集 ............................................................................................................................... 266
分析 ............................................................................................................................... 267
SQLite ..................................................................................................................................... 267
关系型和其他非数据库 ............................................................................................... 269
事件发布 ................................................................................................................................ 270
混合形式 ....................................................................................................................... 271
隔离存储 ................................................................................................................................ 272
总结 ........................................................................................................................................ 272
13 I/O:实战 .................................................................................................................. 273
iPhone 游戏字典 ..................................................................................................................... 273
有趣的属性列表 ..................................................................................................................... 277
二进制属性列表读取器 ............................................................................................... 278
懒加载 ........................................................................................................................... 282
避免中间代码 ............................................................................................................... 284
逗号分隔值 ............................................................................................................................. 287
公共交通调度数据.................................................................................................................. 289
站点信息 ....................................................................................................................... 290
站点停靠时间检索 ....................................................................................................... 291
站点停靠时间导入 ....................................................................................................... 292
更快的CSV 解析 .................................................................................................................... 294
对象分配 ....................................................................................................................... 294
Push 与Pull 的比较 ...................................................................................................... 296
感兴趣的键 ................................................................................................................... 296
并行 ............................................................................................................................... 296
总结 ........................................................................................................................................ 299
14 图像和UI:原理 ........................................................................................................ 301
响应能力 ................................................................................................................................ 301
软件和API .............................................................................................................................. 302
Quartz 和PostScript 图像模型 ............................................................................................... 305
OpenGL .................................................................................................................................. 307
Metal ....................................................................................................................................... 307
图形硬件加速 ......................................................................................................................... 307
从Quartz 到Core Animation .................................................................................................. 311
总结 ........................................................................................................................................ 314
15 图像和UI:测量和工具 ............................................................................................. 315
CPU 分析仪 ............................................................................................................................. 315
Quartz 调试 .............................................................................................................................. 317
Core Animation 工具 ................................................