加快 Windows 或 Cygwin 中 Ruby 脚本的启动速度
我有一个 ruby 脚本,启动大约需要 30 秒。 它需要这么多,因为它试图加载所有库和东西。
当我执行ruby.exe -v
时,它是即时的。
我不想碰原始的 ruby 脚本,它不是我写的。
有哪些技巧可以加快这个过程?
- 我可以预编译它吗?
- 我可以预缓存所有这些文件吗?
我需要在 Windows 或 Cygwin 下执行此操作。
更新:
- 脚本在 Linux/Mac 中也很慢,这种情况并非 Windows 所特有。
- 这是正常的 ruby 1.8.7(其他 ruby 版本中的速度类似)
- 主要瓶颈是加载如此多的库(我删除了不需要的文件和库,并大幅减少了时间,但仍然很慢)
I've got a ruby script which takes about 30 seconds to startup. It takes that much because it tries to load all libraries and stuff.
When I do ruby.exe -v
it's instant.
I don't want to touch the original ruby script, which is not written by me.
What are the tricks to speed this process up?
- Can I precompile it?
- Can I precache all of these files?
I need to do this under Windows or Cygwin.
UPDATE :
- Scripts is quite slow in Linux/Mac as well, this condition is not specific to Windows.
- This is normal ruby 1.8.7 (similar speed in other ruby versions)
- Main bottleneck is loading so many libraries (I removed unrequired files and libraries and decrease the time to drastically but still slow)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为该脚本使用 rubygems? (如果是的话,它会说需要“rubygems”)
您可以尝试安装 minigems(gem install minigems),然后使用 minigems 而不是 rubygems - 应该会加快速度。
I presume the script uses rubygems? (It'll say require "rubygems" if so)
You could try installing minigems (gem install minigems) and then use minigems instead of rubygems - should speed things up a little.
抱歉,无法编译 ruby 脚本。 该脚本正在加载/执行什么操作?
你说得对,30秒是相当长的。 该脚本是否会调用非常昂贵的网络或数据库? 很难相信库需要这么长时间来加载
...我刚刚注意到评论,发现你把它降低到了 1-4 秒...这非常好,尤其是从 30 秒下降时。其他评论是正确的,请将需求发布在脚本顶部
Sorry, but there is no way to compile a ruby script. What sort of stuff is this script loading/doing?
You're right, 30 seconds is quite long. Is this script making calls out to the web or databases that are very expensive? It's hard to believe that libraries would take so long to load
... I just noticed the comments and saw that you got it down to 1-4 seconds...that's very good, especially when coming down from 30. Other comments are right, please post the requires at the top of the script