IDEA's high CPU usage problem solution

Foreword: During this time, I found that IDEA's CPU usage has skyrocketed, and it has soared to 7% or 80% from time to time, which makes the coding experience very bad. After some searching, I finally solved the problem. Record it here

IDEA's high CPU usage problem solution

insert image description here

identify the problem

Let's first locate why IDEA's CPU usage becomes high.

  • Running out of computer memory?
    I also encountered this problem in 2019. At that time, the 8G memory was really not enough to move IDEA. After opening IDEA, the CPU basically ran wildly, and then I changed the memory module and it got better, but Obviously not this time, because after I switched to 32G of memory, it still didn't improve...
  • Too many plugins installed?
    This is an online statement, but I didn't actually install any plug-ins, so I also ruled out
  • Problem with code inspection?
    This is also what the online boss said, but after I turned off some unnecessary code checks, the CPU usage did not go down...

Well, it seems to be in a deadlock, so I turned on the monitoring to see which part of the CPU usage is high

Turn on monitoring
insert image description here

Monitoring content
insert image description here

The result is beyond my expectation. As you can see from the above picture, JIT (just-in-time editing) accounts for the majority, which also explains why the CPU usage soars whenever I am modifying the content of a new code file, because JIT Compiler just-in-time compilation Compiling the class file into local machine code takes up a lot of CPU resources and causes the freeze. Now the problem has been found, and it is time to study the solution.

Solution

After knowing that it is the pot of JIT, we should think about how to solve it. I modified the configuration of the JVM with reference to a blog on the Internet, as shown below:
insert image description here

JVM configuration information
insert image description here
Here I refer to the big brother's settings for the JIT part, but the big brother did not explain the meaning of these parameters in the blog, I will explain it here:

# 堆栈设置

-Xms2048m
-Xmx4096m
-Xverify:none
-XX:+DisableExplicitGC
-XX:ReservedCodeCacheSize=720m
-XX:+UseConcMarkSweepGC
-XX:SoftRefLRUPolicyMSPerMB=50
-ea
-Dsun.io.useCanonCaches=false
-Djava.net.preferIPv4Stack=true
-Djdk.http.auth.tunneling.disabledSchemes=""
-XX:+HeapDumpOnOutOfMemoryError
-XX:-OmitStackTraceInFastThrow

# JIT 参数

# 设置用于编译的编译器线程数
-XX:CICompilerCount=2
# 开启分层编译
-XX:TieredStopAtLevel=1
# 控制最大数量嵌套调用内联
-XX:MaxInlineLevel=3
# 即时编译的东西(没弄懂...)
-XX:Tier4MinInvocationThreshold=100000
-XX:Tier4InvocationThreshold=110000
-XX:Tier4CompileThreshold=120000

-XX:CICompilerCount
By default, the number of threads for the server JVM is set to 2 and the number of threads for the clientJVM is set to 1, if using tiered compilation, the number of threads will be scaled to the number of cores

-XX:TieredStopAtLevel enables
layered compilation

-XX: MaxInlineLevel
defaults to 9, which controls the maximum number of nested calls to be inlined.

The modified CPU usage is shown in the following figure:
insert image description here
insert image description here
It can be seen that the CPU usage of IDEA has dropped significantly.

Reference blog:
Intellij idea CPU usage is too high, too full, running speed is too slow, so five solutions finally succeeded in
idea running cpu100% configuration

PS: You can go to my personal blog to see more content
Personal blog address: Xiaoguan classmate's blog

Guess you like

Origin blog.csdn.net/weixin_45784666/article/details/122057872