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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

How I Made My Ruby Project 10x Faster

97 点作者 jjhageman将近 12 年前

9 条评论

orclev将近 12 年前
Is it wrong that I was secretly hoping the answer was "I rewrote it in something that isn't ruby"?
评论 #6240688 未加载
评论 #6241466 未加载
评论 #6240267 未加载
评论 #6241196 未加载
jfarmer将近 12 年前
alias_method is faster than what he did before because he&#x27;s replicating a bunch of internal logic at run-time, e.g., binding &quot;self&quot; to the correct thing. Somewhere deep in the bowels of the Ruby interpreter it&#x27;s going to be doing the same thing, except it has the opportunity to create the binding statically at define-time. Likewise, he&#x27;s calling a method on a Method object to invoke the original method vs. invoking the original method directly.<p>This might speed things up a little more, too:<p><pre><code> alias_method :&quot;original_#{name}&quot;, name class_eval %{ def #{name}(*args) self.original_#{name}(*args) end } </code></pre> &quot;send&quot; is going to be using extra machinery in the same way, although I think &quot;send&quot; also circumvents certain protections like public&#x2F;private, so I&#x27;m not 100% sure where in the Ruby method invocation process it fits in. &quot;send&quot; might be closer to the metal, but a pre-defined method name would have the opportunity to cache certain things in the invocation process.
scosman将近 12 年前
All of the performance improvements combined were about 0.00002s per call. They came at the cost of simplicity.
评论 #6241046 未加载
评论 #6241030 未加载
评论 #6240281 未加载
评论 #6240274 未加载
aneth4将近 12 年前
Sort of takes away from the &quot;power&quot; and &quot;beauty&quot; of the language when you need to dissect your code and understand the runtime to get reasonable performance.
评论 #6242965 未加载
Pxtl将近 12 年前
tl;dr: bolting on a dynamic-typed imitation of static-typing is slow.
评论 #6241049 未加载
评论 #6240900 未加载
blakeshall将近 12 年前
I really enjoy write-ups like these. Anyone have a resource that is primarily blog posts&#x2F;articles like this?
评论 #6241373 未加载
nfm将近 12 年前
Does anyone know what&#x27;s going on behind the scenes with `alias_method`? I&#x27;m curious to know how it&#x27;s implemented such that it was actually faster!
mosselman将近 12 年前
Would have been more useful if there were more before-after examples.
Demiurge将近 12 年前
Did you rewrite it in Go? I guess I should read the article.<p>OK, now that I&#x27;ve read it, profiling ftw :-)