SoFunction
Updated on 2025-03-04

IDEA performance optimization method solves lag problem

Preface

When we use IntelliJ IDEA, we sometimes feel stuck. So how can we make IntelliJ IDEA better without upgrading the computer configuration?

We can optimize IntelliJ IDEA by modifying some settings of IntelliJ IDEA. Optimizing IntelliJ IDEA's performance can significantly improve development efficiency and reduce unnecessary waiting time

The following measures can be taken

  1. Make sure the IDEA version is up to date, as the JetBrains team continues to fix performance issues and introduce performance improvements in new releases.
  2. Adjust memory allocation: By modificationFile, increase IDEA's memory limit, for example-Xmx2048mand-Xms512mAdjust to the value that suits your machine configuration.
  3. Management plug-in: Disable or uninstall infrequently used plug-ins to reduce the startup time and memory usage of the IDE.
  4. Optimize index settings: Reduce the number of indexed items, for exampleSettings > Editor > General > Editor TabsAdjust the number of "Marking Occurrences".
  5. Configure the build system: Make sure the build system is configured correctly, such as Gradle or Maven, and distributed using local build tools.
  6. Exclude unnecessary files: Configure exclusion rules so that IDEA does not index specific folders or file types.
  7. Code analysis on demand: Avoid frequent full-project analysis, manually trigger or perform smaller-range analysis.
  8. Enable Smart Mode:passSettings > Appearance & Behavior > AppearanceEnable "Low Memory" mode to reduce rendering and animation effects.
  9. Optimize integration of external tools: Adjust the configuration of external tools, such as Git'sgcset up .
  10. Enable hardware acceleration:existSettings > Appearance & Behavior > AppearanceEnable hardware acceleration to improve UI response speed.
  11. Avoid frequent full loading:useFile > Invalidate Caches / Restart...Clear the cache and restart IDEA, but avoid frequent use.
  12. Performance monitoring:passHelp > Edit Custom VM OptionsOpen the Performance Monitoring dialog box and adjust the JVM parameters to identify and resolve performance bottlenecks.
  13. Custom shortcut keys:passSettings > KeymapCustomize shortcut keys to reduce mouse operation and improve work efficiency.
  14. Avoid automatic import:existSettings > Editor > General > Auto ImportDisable automatic import in the process to reduce the burden of background processing.
  15. Restrict background tasks:existSettings > Appearance & Behavior > System Settings > Power Save ModeEnable power saving mode in the background to restrict the tasks IDEA performs in the background.
  16. Use offline mode: When needed, passHelp > Edit Custom VM OptionsEnable offline mode to reduce network dependencies.
  17. Code editing optimization: Turn off or adjust code editing functions, such as "Code Completion", "Live Templates", etc. to reduce resource consumption.
  18. Build configuration optimization: Configure different build settings for different development environments, such as using different JDK versions or build tools configuration.
  19. Avoid global search: Use limited scope searches instead of global searches to save resources.
  20. Regular maintenance: Carry out disk cleaning, database maintenance and index reconstruction to maintain IDEA's operating efficiency.
  21. Using an external editor: For large files, open with an external editor to avoid loading in IDEA.
  22. Code warehouse optimization: Optimize Git or SVN settings, for example through.git/configConfiguration files limit the loading of history.
  23. Restrict automatic updates:existSettings > Appearance & Behavior > System Settings > UpdatesAdjust automatic update settings to reduce network and CPU burden.
  24. Adjust editor rendering:existSettings > Editor > FontAdjust the font size and anti-aliasing settings to improve the rendering speed of the editor.
  25. Using external build tools: For large build tasks, consider using external build tools such as the command line version of Maven or Gradle.

Parameter explanation of VM Options

IntelliJ IDEA's VM Options allows you to configure parameters of Java virtual machines at startup to control application behavior and performance.

These options are stored inIn the file, it is usually located in the installation directory of IntelliJ IDEAbinin folder.

Here are some commonly used VM Options parameters:

1. Memory settings

  • -Xms: Sets the initial heap size of the Java virtual machine. For example,-Xms512mSet the initial heap size to 512MB.
  • -Xmx: Set the maximum heap size of the Java virtual machine. For example,-Xmx2gSet the maximum heap size to 2GB.
-Xms512m
-Xmx2g

Increase-XmxParameters can improve the performance of IntelliJ IDEA, especially when dealing with large projects.

2. Performance Tuning

-XX:ReservedCodeCacheSize:

  • Sets the size reserved for the code cache.
  • By default, IDEA allocates a certain amount of space for the code cache, and you can increase this space size as needed to improve compilation performance.
-XX:ReservedCodeCacheSize=512m

-XX:MaxPermSize(Deprecated):

  • Used to set the maximum size of the permanent generation in earlier versions of Java.
  • In Java 8 and later, the permanent generation has been replaced by metaspace.

3. GC (garbage recycling) optimization

-XX:+UseConcMarkSweepGCand-XX:+UseParNewGC: Enable parallel garbage collector, suitable for large memory and multi-core processors.

-XX:+UseConcMarkSweepGC
-XX:+UseParNewGC

-XX:NewRatio:

  • Set the ratio of the new generation to the old generation.
  • For example,-XX:NewRatio=3It means that the new generation takes up 1/4 of the heap space.
-XX:NewRatio=3

4. Debugging and Diagnosis

  • -XX:+HeapDumpOnOutOfMemoryError: Automatically generate a heap dump file when memory overflows, which is used to analyze memory problems.
-XX:+HeapDumpOnOutOfMemoryError
  • -XX:HeapDumpPath: Specifies the generation path of the heap dump file.
-XX:HeapDumpPath=/path/to/dump/directory

5. Other settings

-DThe parameters at the beginning can set system properties.

like-=UTF-8Used to specify that the file is encoded as UTF-8.

-=UTF-8

6. Steps to set up VM Options

  1. Open IntelliJ IDEA.
  2. Click on the top menuHelp -> Edit Custom VM Options
  3. In the open file, edit or add the parameters you need.
  4. Save the file and restart IntelliJ IDEA to make the settings take effect.

By configuring these VM Options parameters properly, you can optimize the performance and behavior of IntelliJ IDEA, especially when handling large projects and complex operations to improve development efficiency and experience.

Summarize

Through the above measures, the performance of IntelliJ IDEA can be significantly improved and makes it more suitable for the development needs of large-scale projects.

The above is personal experience. I hope you can give you a reference and I hope you can support me more.