编程与软件工程agner.org编辑精选
软件优化资源:C++、汇编、Windows、Linux、BSD、macOS
Software optimization resources for C++, assembly, Windows, Linux, BSD, Mac OS
2015 — 2024,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这是 Agner Fog 维护的软件优化资源合集,涵盖 C++、汇编以及 Windows、Linux、BSD、Mac OS 等平台的优化手册,包括微架构分析和指令延迟表等文档。它多年来被 Hacker News 反复推荐,是底层性能优化领域公认的权威参考。
为什么经久不衰:Agner Fog 对 Intel/AMD 微架构的深入分析无人能出其右,这些手册历经多年更新仍是最可靠的底层优化参考资料。
HN 评论精选
高层算法和领域知识层面的优化收益远大于底层微优化,且应先建立测量基准
根据我的经验,最大的优化收益来自把更多领域知识引入代码:用启发式方法减少昂贵函数的执行次数、引入足够好的近似捷径、对数据中实际不变的值做预计算和记忆化等。对于从未优化过的程序,通常用性能分析器很容易发现明显糟糕的问题,比如在紧凑循环里反复初始化本可以做成单例的昂贵对象。我曾花一个月把一段没人优化过的代码的 CPU 开销降低了整整 100 倍。另外,一定要先建立可靠的性能测量框架,再开始优化。底层硬核优化很少值得投入。
H8crilA查看英文原文
From my experience the greatest optimization gains can be achieved by introducing more domain knowledge into the code. Heuristics that cut the number of executions of some expensive function, shortcuts that introduce good enough approximations, pre-computing and memoizing certain values that are actually constant in the processed data. Things like that. And in programs that had never been optimized it's usually very easy to fire up the profiler and find some obviously terrible things. Like reinitializing in a tight loop some expensive object that can easily be a singleton (or at least a thread local object). I've once spent a month on a decent piece of code and brought down the CPU cost by literally 100x (nobody had optimized the code before). Also, always, first create a reliable framework for measuring progress (cpu instruction retired counters in Intel CPUs are very good and don't need a lot of execution repetitions to bring the p-values low), and only then start optimizing. Low-level, hardcore optimization rarely pays out (not never, but rarely).
Agner 的微架构与指令时序文档是底层优化者的必备权威资料
就我所知,在可以自由写作的作者中,Agner 对 Intel 和 AMD 微架构的了解无人能及。他的指南,尤其是微架构和指令时序文档,是任何认真做底层优化的人都应常备的绝佳资源。
stephencanon查看英文原文
Anger knows more about Intel and AMD microarchitecture than anyone else I'm aware of who's allowed to write about it freely. His guides, especially his microarchitecture and instruction timing documents, are superb resources that anyone serious about low-level optimization should have on hand.
Agner 的文档是常用参考,但实际优化仍需自己反汇编和实测验证
我经常参考他的《微架构》文档寻找优化思路,也会用 Intel 的优化手册和 IACA 工具。但我总会亲自反汇编并对不同方案做 A/B 计时验证。
CalChris查看英文原文
I use his Microarchitecture regularly for ideas. Also Intel's Optimization manual and their IACA tool. But I always disassemble and A/B time things.
即使是小数组的简单查找循环,底层优化也充满权衡,并不简单
我最近尝试优化一个在 8 个短整数的小数组中查找值的循环,并不容易,可选方案太多了:紧凑循环(先验上未必最优但只占一条指令缓存行)、展开循环、用 cmov、还是 SIMD?
renox查看英文原文
I tried recently to optimise a loop looking for a value in a small array of short integers (8 elements), not so easy, there are so many choices: tight loop (a priori not an optimal choice but use only one instruction cache line), unrolled loop, using cmovs, SIMD?
历次讨论
同类还值得读
开源应用架构
The Architecture of Open Source Applications
《开源软件架构》(AOSA)是一本在线免费书,邀请知名开源项目的作者亲自剖析其内部设计,涵盖 SQLAlchemy、LLVM、Audacity、Apache、Bash 等系统。
编程与软件工程上首页 9 次 · 2011–2024aosabook.org编辑精选编程语言简史:简短、不完整且多半错误
A Brief, Incomplete, and Mostly Wrong History of Programming Languages
一篇以戏谑、故意不准确的方式回顾编程语言史的博客文章,用夸张轶事和讽刺定义串起 Lisp、C、C++、Java、JavaScript、PHP 等语言。
编程与软件工程上首页 8 次 · 2009–2021james-iry.blogspot.comSQLite 是如何测试的
How SQLite is tested
SQLite 官方文档页,系统介绍 SQLite 的测试体系:多种测试方法(TCL 测试、模糊测试、回归测试、静态分析等)和海量测试用例,展示了这个小型开源项目如何靠极致测试获得…
编程与软件工程上首页 8 次 · 2009–2025sqlite.org编辑精选高级编程语言(2009)
Advanced programming languages (2009)
Matt Might 的经典文章,按用途推荐“高级编程语言”:如果追求就业就选主流语言,如果追求表达力、学术研究或创业,则推荐 Haskell、OCaml、Scala 等函数式语…
编程与软件工程上首页 8 次 · 2009–2022matt.might.net我的 Forth 与栈机器经历
Yosefk - My history with Forth & stack machines
作者以亲身经历回顾了使用 Forth 语言和栈式机器的历程:既赞叹其简洁优雅、代码量小、可自举的优点,也坦率指出栈操作在实际编程中的痛苦,以及 Forth 社区文化中的问题。
编程与软件工程上首页 8 次 · 2010–2024yosefk.com编辑精选