TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Tell HN: Optimization is only premature when the expected profit is negative

4 点作者 pc2g4d将近 3 年前
Many optimizations are dismissed as irrelevant and &quot;premature&quot;. But, for enterprises with finite cash to throw at hardware, fewer optimizations are premature than is often assumed.<p>Use less memory, use less CPU, and you can get more instances running on a single machine.<p>RiiR, switch to a unikernel, etc. same thing.<p>But only real optimization counts---real reductions in resource usage. Not things you believe _should_ make things faster or lighter; only things that _do_.<p>But if the optimization costs you more in developer time than will be reclaimed in operations costs over the _entire lifetime of the code_... then it is premature.<p>Estimating this, though, is a challenge.<p>Just stating the obvious, I suppose.

5 条评论

drKarl将近 3 年前
Optimized code takes longer to write and is often more complex and less readable and less maintainable. Since software engineer salaries costs are higher than hardware costs it would take way longer and cost more to optimize all code.<p>When you&#x27;re writing code sometimes you need to refactor, requirements change etc.<p>You may focus on optimizing code for saving 3 nanoseconds on code that doesn&#x27;t run that often.<p>Optimization is important, and can save money on hardware resources, but focusing on the wrong things to optimize can be costly and make the application more difficult to maintain.<p>Once you identify the bottlenecks of the application you can focus on optimizing these.<p>Obviously that doesn&#x27;t mean you should throw away resources, so it&#x27;s always a good idea to use static analysis in combination with code reviews to avoid unnecessary use of resources, like repeatedly doing a costly operation in a loop that always yields the same result (it can be done before the loop starts, or you can memoize&#x2F;cache the result to reuse it), caching network&#x2F;database requests that are expected to return the same data, use a connection pool for expensive resources like database connections...<p>But more advanced optimization should be reserved for bottlenecks.
评论 #32149848 未加载
niros_valtos将近 3 年前
The problem with skipping major optimizations is that the tech debt grows with time.<p>The ROI calculation is tough, but there are things the simply make sense by looking at the data, e.g. find underutilized resources based on the native tools in the cloud infrastructure environment.
compressedgas将近 3 年前
That only gets you to a local minima. The point of avoiding premature optimization is to avoid optimizations that you&#x27;ve done making things too complex for you to be able to get to global minima for the problem your code is solving.
dave4420将近 3 年前
No, because there is also opportunity cost to consider.
scrapheap将近 3 年前
Sorry, I must be missing something as I can&#x27;t see what you&#x27;re saying that&#x27;s different to don&#x27;t optimize prematurely.
评论 #32148908 未加载