摘要:"过早优化是万恶之源"(Premature optimization is the root of all evil)是软件开发领域广为流传的名言,提醒开发者应避免在未明确需求前过度设计解决方案。
来源:raw/【收集箱】/过早优化是万恶之源.md
最后更新:2026-06-27
这句话源自计算机科学家唐纳德·克努特(Donald Knuth),他在 1974 年的论文 Structured Programming with go to Statements 中写道:
"We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil."
过早优化在实际项目中常见的例子:
过早优化的本质是在尚未了解真正的瓶颈之前就投入大量资源进行优化。类比而言,就像还没开始一项爱好,就花大量时间和金钱挑选最好的装备。
但这并不意味着忽视性能——而是在正确的时机以正确的方式关注性能。先让功能正确运行,衡量实际性能,再针对真正的瓶颈进行优化。