搞清楚哪些Gems Rails应用程序不使用 [英] Figuring Out Which Gems Rails App Does Not Use

查看:83
本文介绍了搞清楚哪些Gems Rails应用程序不使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

开发一款拥有近200颗宝石的应用程序。有没有人想过如何隔离未使用的宝石,以便将它们从组合中取出。 Ruby的动态本质,不可能确定是否在没有测试的情况下使用宝石。虽然没有很好的理由在临时加载它们是不好的做法,但在程序执行过程中的任何时候都可能需要一个gem。它们不需要预先加载。

尽管按需加载gem可能有优势,例如,保持较低的内存占用量并减少启动时间,它确实很难确定它们是否在实际使用或在哪里实际使用。



宝石名称和它使用的方法之间并不总是相关的。虽然很多人都有一个很容易被人理解的名称空间,但是有些人只是将方法添加到现有的类中,这可能会使得追踪它们变得复杂,特别是如果他们甚至用旧的方法修补具有相同名称的新方法。 b
$ b

如果您可以通过单元,功能和集成测试来运用大部分应用程序,则可以使用 ruby​​-prof 至少可以了解使用哪些宝石。这可以使识别候选人更容易移除。


Working on an app that has almost 200 gems. Has anyone figured out how to isolate gems that are not used so they can be taken out of the mix.

解决方案

Due to the dynamic nature of Ruby, it's not possible to know for sure if a gem is or isn't used without testing. Although it is bad practice to load them in ad-hoc without a good reason, it is possible to require a gem at any point in the execution of the program. They do not need to be loaded up-front.

Although there might be advantages to loading gems on demand, for instance, keeping a lower memory footprint and reducing launch times, it does make it difficult to determine if or where they are actually used.

There isn't always a correlation between a gem name and the methods it uses. While many have a namespace that's easily grepped for, some just add methods to existing classes which can complicate tracking them down, especially if they go so far as to patch out old methods with new ones that have the same name.

If you are able to exercise a large portion of the application through your unit, functional, and integration tests it might be possible to use ruby-prof to at least get a sense of which gems are used. That could make identifying candidates for removal easier.

这篇关于搞清楚哪些Gems Rails应用程序不使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆