如何确定是什么导致 Eclipse 变慢?
我们有相当大的代码库(150 多个项目、400000 多行 Java 代码、一些 Groovy 和 Gradle 代码、一些 Perl 代码、一些 XML、大量 JSP 等)。我设法在 Spring Tools Studio 2.6 中打开所有这些项目,并向其中添加了一些 Groovy、Perl、Checkstyle、PMD 插件。
问题是 Eclipse 一直让我的 CPU 忙碌。当我更新某些东西时,它真的很慢,它的构建速度很慢,任何类型的 UI 操作都会发生延迟。
另外,我有相当好的 64 位机器,8GB RAM,我运行 64 位版本的 STS,我给 Eclipse 分配了 2GB(但无论如何它都不会高于 1GB 堆)。
所以,我的第一个问题是有没有办法确定是什么导致速度变慢?你们中的一些人是否成功地在单个工作区中处理如此庞大的代码库?
我尝试查看运行 Eclipse 的 JVM 的线程(使用 jconsole),但我找不到任何有趣的东西。
We have rather large code base (150+ projects, 400000+ lines of Java code, some Groovy and Gradle code, some Perl code, some XML, a lot of JSPs etc.). I managed to open all those projects in Spring Tools Studio 2.6 to which I also added some plugins for Groovy, Perl, Checkstyle, PMD.
And the problem is that Eclipse is holding my CPU busy all the time. And it's really slow when I update something, it's building slowly, any kind of UI operations happen with a delay.
Also I have rather good machine 64-bit, 8GBs of RAM and I run 64-bit version of STS and I give 2GBs to Eclipse (but it does not get higher that 1GB of heap anyway).
So, my first question is there a way to determine what is making it slow? And do some of you guys have succeded in working with such large code bases in a single workspace?
I have tried looking at the threads (using jconsole) of the JVM that runs Eclipse, but I can't find anything intersting there.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我将提出一些建议——这些建议是按照容易程度排列的。如果您一心想弄清楚它是什么插件,然后加入该项目来修复它或向支持列表发送仇恨邮件,那么您可能想跳到下面的“分析它”。
检查控制台
如果您从命令行启动 eclipse(即输入
eclipse
),那么如果抛出任何异常,您将在此处看到它们。有时,缓慢可能是由于插件反复失败并抛出大量异常而导致的。有时这是您可以修复的问题 - 有时您必须删除该插件。提升你的 RAM
我们喜欢 GC,但它会导致缓慢的死亡。 GC 的美妙之处在于你的程序永远不会耗尽内存——因为用户认为它已经锁定并在它实际耗尽内存之前杀死它。因此,请尝试增加 PermGen 和其他 Eclipse 内存设置: http://wiki.eclipse.org/FAQ_How_do_I_increase_the_heap_size_available_to_Eclipse%3F
创建一个
我经常放弃的 新工作区只需删除/重新创建整个工作区即可。有如此多的插件,这对调试来说是一个真正的挑战,而且通常它会在工作区目录中产生垃圾,从而使事情变得混乱。
保持 Eclipse 的精简
如果我想让 Eclipse 真正敏捷,我将为单个项目创建一个安装并仅添加所需的插件。如果您可以从非 EE 版本开始,那么您已经不再那么臃肿了。
分析
Sun JDK 中包含的 VisualVM(您可能已经安装了它。)可用于查看哪些类消耗了最多的处理器时间以及哪些对象占用了内存(以及创建它们的对象)。
启动 VisualVM,您应该会看到应用程序中列出了 Eclipse。右键单击 Eclipse 条目并在 VisualVM 中“打开”Eclipse。您现在可以附加一个探查器并查看正在使用哪些类。
分析会减慢一切速度(很多!),因此您可能希望从尽可能小的示例开始 - 或者要非常耐心。特别是在分析开始时,它会花费很长时间,因为它“检测”类(注入字节码以允许分析)。
I'll make a few suggestions - these are in order of easiness. If you are hell bent on figuring out what plugin it was and either joining that project to fix it or send hate mail to a support list, then you probably want to skip to "Profile It" below.
Check the console
If you start eclipse from the command line ( ie type
eclipse
) then if there are any exceptions being thrown you'll see them in here. Sometimes slowness can be caused by a plugin repeatedly failing and throwing lots of exception. Sometimes it is something you can fix - sometimes you have to remove that plugin.Boost your RAM
We love GC but it causes a slow death. The beauty of GC is that your program never runs out of memory - because the user thinks it has locked up and kills it before it actually runs out of ram. So, try increasing the PermGen and other Eclipse memory settings: http://wiki.eclipse.org/FAQ_How_do_I_increase_the_heap_size_available_to_Eclipse%3F
Create a new Workspace
I often give up and just delete/recreate the whole workspace. There are so many plugins there is can be a real challenge to debug and often it garbage in the workspace directory that keeps things breaking.
Keep Eclipse Lean
If I want to keep Eclipse really snappy, I'll create an install for a single project and add only the plugins needed. If you can start from the non-EE version you're already far less bloated.
Profile It
The VisualVM that is included in with the Sun JDK (you probably already have it installed.) can be used to see what classes are consuming the most processor time and which objects are taking up memory (and what created them).
Start VisualVM up, and you should see Eclipse listed in the Applications. Right click on the Eclipse entry and "Open" Eclipse inside VisualVM. You can now attach a profiler and see what classes are being used.
Profiling will slow everything down (a lot!) so you might want to start with the smallest possible example you can - or be extremely patient. Especially at the start of profiling it will take a long time as it 'instruments' the classes (injecting bytecode to allow profiling).
了解 Eclipse 正在做什么的一种方法是启用调试。 这里有一些关于调试 Eclipse 构建器的信息,但是过程是通用的,即您需要从命令行启动 eclipse $eclipsec –debug > log.txt 并使用 .options 文件启用某些插件的调试。我想您会想仔细研究一下“更新”和“构建”操作。
另一种选择是使用工具,例如 MAT(内存分析器)、YourKit。我发现 YourKit 非常有用,例如,您可以在 YourKit 中启用 CPU 分析,然后在 Eclipse 中执行您认为需要花费大量时间的操作。操作完成后,您可以拍摄快照并在 YourKit 中进行一些分析。需要注意的是,将 YourKit 分析器附加到 Eclipse 会进一步减慢 Eclipse 的速度。
话虽如此,在一个工作区中运行 150 多个项目还是有点多。如果可能的话,您应该为每个组件设置一个工作区以及目标平台中的其余插件。您的所有工作区都可以共享一个目标平台。对于 150 多个项目,仅构建完整的工作区就可能需要相当长的时间,因为必须生成大量类文件,这意味着大量的磁盘 IO,而 eclipse 无法帮助您,只有 SSD 可以:)
One way to know what Eclipse is doing by enabling debugging. There is some information here about debugging eclipse builders, however the process is generic i.e. you need to start eclipse from command line $eclipsec –debug > log.txt and enable debugging for certain plugins using the .options file. I guess you would want to look a bit closely at 'update' and 'build' operations.
Another option would be to use a tool, e.g. MAT (Memory Analyzer), YourKit. I find YourKit to be quite useful, you could for example enable CPU profiling in YourKit and then perform an action in Eclipse which you feel is taking a lot of time. Once the action completes, you can take a snapshot and do some analysis in YourKit. A caveat is that a attaching the YourKit profiler to Eclipse will further slow down Eclipse.
Having said that 150+ projects in one workspace is a bit much. If it is possible you should probably setup one workspace per component with the rest of the plugins in a target platform. All your workspaces can share a single target platform. With 150+ projects a full workspace build alone can take quite a bit of time since a large number of class files have to be generated which means a large amount of disk IO, and eclipse cannot help you there only a SSD can :)
Eclipse 2019-09提出了一种新方法:
Eclipse 2019-09 proposes a new way: