Rails:i18n,如果我将整个应用程序转换为本地化,我的性能是否会受到巨大影响?
只是想知道,因为对于每个视图/控制器/所有内容中的每个字符串,它都必须进行额外的查找来替换占位符。很恼火,这些替代品中的每一个都很快……但是……有人注意到重大的性能问题吗?
Just wondering, because for every string in every view / controller / everything, it has to do an extra look up to replace the placeholder. Grated, each of these replacements is balls fast... but.. has anyone noticed significant performance issues?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当 Rails 加载时,它会将您的区域设置文件加载到内存中,这意味着时间成本接近于在内存中查找所需的时间。根据我的经验,这并没有将应用程序的速度减慢到可感知的水平。这是一个基准或排序:
Benchmark.realtime { 10000.times { I18n.t(:hello) } } # => 0.834578037261963
Benchmark.realtime { 10000.times { String.new("hello") } } # => 0.00372004508972168
尽管第二个基准测试没有做太多事情,但对 I18n 的 10000 个请求仍然会导致不到一秒的时间。
When rails loads, it will load up your locale file into memory meaning the cost of time is close to the amount of time it takes to do an in memory lookup. From my experiences this hasn't slowed down an application to a perceivable level. Here is a benchmark or sorts:
Benchmark.realtime { 10000.times { I18n.t(:hello) } } # => 0.834578037261963
Benchmark.realtime { 10000.times { String.new("hello") } } # => 0.00372004508972168
Granted the second benchmark isn't doing a lot, 10000 requests to I18n still results in under a second of time.