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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Making a Go program 70% faster by avoiding common mistakes

147 点作者 numo16大约 9 年前

9 条评论

rndstr大约 9 年前
Great job. The title was misleading to me because I thought I&#x27;d learn something about Go but this basically boils down to these performance improvements<p><pre><code> - store results in variables and don&#x27;t call the expensive method over and over - use batch queries for fetching multiple documents at once from your storage</code></pre>
评论 #11304128 未加载
评论 #11303456 未加载
评论 #11303341 未加载
评论 #11303770 未加载
评论 #11304342 未加载
echlebek大约 9 年前
Benchmarks are an important part of optimizing a program.<p>Another important part of optimization is profiling. Profiling lets you see where your program is spending the bulk of its time. Then you can make informed decisions about where to direct your efforts.<p><a href="https:&#x2F;&#x2F;blog.golang.org&#x2F;profiling-go-programs" rel="nofollow">https:&#x2F;&#x2F;blog.golang.org&#x2F;profiling-go-programs</a>
rileymat2大约 9 年前
A bit off topic, but do we have a standard way to talk about performance improvements in terms of percents?<p>This went from 131 to 76. The 70% calculation was (start-end)&#x2F;end. Is this the standard method, because it seems like you would divide by the start timing.
评论 #11304184 未加载
评论 #11304530 未加载
评论 #11304281 未加载
egeozcan大约 9 年前
I&#x27;m not against people posting their experiences about finding issues (even if trivial) in their code or learning something fundamental about db queries - I would actually encourage that. What I find a bit annoying is putting the name of the programming language they use front and center, as if it was relevant at all, to attract what is mostly called as &quot;hype&quot;.
评论 #11306336 未加载
speps大约 9 年前
Interesting tool suggested in the comments of the article : <a href="https:&#x2F;&#x2F;github.com&#x2F;uber&#x2F;go-torch" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;uber&#x2F;go-torch</a>
blablabla123大约 9 年前
&gt; [Go] benchmarks are your friend<p>&gt; Try not to query your database if possible.<p>Actually this is quite generic and applies to any platform...
al2o3cr大约 9 年前
I&#x27;d also recommend that the author look into tidying up the `TransactionType` field at ingest - those `ToLower` calls aren&#x27;t free either, and if you&#x27;ve got control of the system writing the data it&#x27;s easier to just store a consistent case.<p>Failing that, `EqualFold` may be worth looking at. It expresses the same intent, dunno if it&#x27;s more or less efficient.
unfunco大约 9 年前
I&#x27;m not sure if Go optimises your condition, but you&#x27;re calling strings.ToLower(trade.TransactionType) twice, you could memoize the result of that operation and possibly squeeze a little more performance out of the impact function.
meshko大约 9 年前
Sadly the important wisdom is missing from the post -- profile, then optimize.