尽管按需加载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应用程序不使用
发布评论