2008-04-17
The smallwig theory of optimization
关键字: optimization
There are three kinds of optimization.
1. Optimization by using a more sensible overall approach.
2. Optimization by making the code less weird.
3. Optimization by making the code more weird.
You've probably heard, and maybe even spouted yourself, the phrase "premature optimization is the root of all evil." It's exclusively "Type 3 optimization" that this aphorism applies to. Types 1 and 2 are quite fine to engage in pre-emptively.
To make a type 3 optimization, your burdens are six:
1. Thou shalt have excellent, comprehensive unit tests.
2. Thou shalt have a reliable benchmark, based on representative inputs.
3. Thou shalt demonstrate that your change improves the benchmark.
4. Thou shalt successfully argue that this improvement really matters.
5. Thou shalt comment the code.
6. In nontrivial cases, thou shalt also preserve the clear-but-slow implementation, to use in parity tests with your optimized implementation.
In all things, remember these truths:
1. Your brain is a terrible profiler.
2. Hotspot will outsmart you.
3. It just doesn't matter, until it matters.
If you believe this post, please spread the word!
1. Optimization by using a more sensible overall approach.
2. Optimization by making the code less weird.
3. Optimization by making the code more weird.
You've probably heard, and maybe even spouted yourself, the phrase "premature optimization is the root of all evil." It's exclusively "Type 3 optimization" that this aphorism applies to. Types 1 and 2 are quite fine to engage in pre-emptively.
To make a type 3 optimization, your burdens are six:
1. Thou shalt have excellent, comprehensive unit tests.
2. Thou shalt have a reliable benchmark, based on representative inputs.
3. Thou shalt demonstrate that your change improves the benchmark.
4. Thou shalt successfully argue that this improvement really matters.
5. Thou shalt comment the code.
6. In nontrivial cases, thou shalt also preserve the clear-but-slow implementation, to use in parity tests with your optimized implementation.
In all things, remember these truths:
1. Your brain is a terrible profiler.
2. Hotspot will outsmart you.
3. It just doesn't matter, until it matters.
If you believe this post, please spread the word!
发表评论
- 浏览: 42881 次
- 性别:

- 来自: 北京

- 详细资料
搜索本博客
我的相册
Snap1
共 1 张
共 1 张
最新评论
-
使用Atomikos Transaction ...
引用Caused by: com.atomikos.icatch.SysExce ...
-- by bagui3 -
Struts2中使用Stream Res ...
Stream result type? 可有可无,把Respose的header ...
-- by ray_linn -
Struts2中使用Stream Res ...
我的程序,虽然结果出来了,但后台总是抛错:------------------- ...
-- by Acaleph -
使用Atomikos Transaction ...
Caused by: com.atomikos.icatch.SysExcept ...
-- by baoyaer -
Annotation风格的Spring M ...
刚用了spring MVC的annotation, 确实简单。应该说在简化问题上 ...
-- by slaser






评论排行榜