(评论)
(comments)
原始链接: https://news.ycombinator.com/item?id=39564632
用于学习性能优化的推荐资源包括:
1. 书籍,例如《每台计算机性能书籍》、《现代硬件算法》和《底层实现的定量理解》。
2. 在线资源,例如 MIT 的公开课程 6.172:软件系统的性能工程、Casey Muratori 撰写的博客、Brendan Gregg 的博客以及 Nicolas Nethercote 的 Rust Performance Book。
3. 学习如何测量和建模性能以及使用跟踪库、Linux perf 和 ebpf 工具化代码。
4. 观看视频、运行 Lighthouse 并利用调试器调查性能问题。
5. 优先寻找真实世界的代码并衡量其性能。
6.学习CPU缓存等基础知识并了解基本事物的数量级。
7.警惕复杂循环、嵌套循环和涉及远程调用的循环。
8. 请记住,当您在优化层次中向下推进时,潜在收益会迅速减少。
9.寻找机会消除不必要的任务,而不是仅仅专注于优化工作。
在优化原则方面,考虑避免在单个执行流中重复网络请求,谨慎考虑循环的复杂性(尤其是嵌套循环和远程调用循环),围绕CPU缓存设计应用程序,并牢记基本的数量级。 计算元件等。 此外,优先考虑确保适当进行绩效评估。
1. First and foremost: measure early, measure often. It's been said so often and it still needs repeating. In fact, the more you know about performance the easier it can be to fall into the trap of not measuring enough. Measuring will show exactly where you need to focus your efforts. It will also tell you without question whether your work has actually lead to an improvement, and to what degree.
2. The easiest way to make things go faster is to do less work. Use a more efficient algorithm, refactor code to eliminate unnecessary operations, move repeated work outside of loops. There are many flavours, but very often the biggest performance boosts are gained by simply solving the same problem through fewer instructions.
3. Understand the performance characteristics of your system. Is your application CPU bound, GPU compute bound, memory bound? If you don't know this you could make the code ten times as fast without gaining a single ms because the system is still stuck waiting for a memory transfer. On the flip side, if you know your system is busy waiting for memory, perhaps you can move computations to this spot to leverage this free work? This is particularly important in shader optimizations (latency hiding).
4. Solve a different problem! You can very often optimize your program by redefining your problem. Perhaps you are using the optimal algorithm for the problem as defined. But what does the end user really need? Often there are very similar but much easier problems which are equivalent for all practical purposes. Sometimes because the complexity lies in special cases which can be avoided or because there's a cheap approximation which gives sufficient accuracy. This happens especially often in graphics programming where the end goal is often to give an impression that you've calculated something.
reply