知识卡片
可见分配应按测量决定优化
显式clone、to_vec和Box::new让成本更容易看见,但可见不等于值得优化掉。优先使拥有关系与接口清楚,再按真实基准定位重要复制;大值Copy的隐式成本也要考虑。no_std不必然禁止堆分配,支持alloc的目标可提供不同折中。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 3. Concepts Who’s Afraid of the Big Bad Copy? · 查看原书依据
Making an allocation or copy operation visible rather than hidden isn’t a good reason to optimize it away, especially if that happens at the expense of usability. In many situations, it makes more sense to focus on usability first, and fine-tune for optimal efficiency only if performance is genuinely a concern—and if benchmarking (see Item 30) indicates that
参考来源
- 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第3章《Who’s Afraid of the Big Bad Copy?》(spine7;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch03.html;u111-ch03-051)。
- 结论依据:原文在“Making an allocation or copy operation visible”附近的定义、例子或代码支撑本卡核心说明:显式clone、to_vec和Box::new让成本更容易看见,但可见不等于值得优化掉。边界按已读前提解释;示例未执行。
- 原始内容:Making an allocation or copy operation visible rather than hidden isn’t a good reason to optimize it away, especially if that happens at the expense of usability. In many situations, it makes more sense to focus on usability first, and fine-tune for optimal efficiency only if performance is genuinely a concern—and if benchmarking (see Item 30) indicates that