编译过程内存过高
========

**问题现象**

编译构建时，内存或CPU占用过高，导致DevEco Studio运行卡顿和延迟。

**解决措施**

*   在执行hvigor构建的过程中，通过减少内存中的缓存数据、减少线程数量，可以减少编译过程中的内存占用。
    
    可以在hvigor-config.json5中添加配置。
    
    {
      "modelVersion": "0.0.1",
      "dependencies": {},
      "properties": {
        // Set to 0, indicating that the memory cache configuration is not enabled. The default value is 4, and the lower the value, the less cached data in memory
        "hvigor.pool.cache.capacity": 0,
        // The default configuration is -1 CPU cores, including ohos.arkCompile.maxSize4. The smaller the value, the less memory it occupies
        "hvigor.pool.maxSize" : 5,
        // The default configuration value is 5, and the smaller the value, the less memory it occupies
        "ohos.arkCompile.maxSize": 3,
        // The default configuration value is true, indicating that the memory cache is turned on and occupies more memory. The configuration is false, and the memory cache is turned off and occupies less memory
        "hvigor.enableMemoryCache": false
      }
    }
    
    ![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/71/v3/yutms18ISZKN24LtM0dypQ/note_3.0-zh-cn.png?HW-CC-KV=V1&HW-CC-Date=20260612T074812Z&HW-CC-Expire=86400&HW-CC-Sign=448C9A57CAFDE9073A460617075C5B033AF3EC16849DCAA69DFD9D7CD24B60ED)
    
    当配置项"hvigor.pool.maxSize"和"ohos.arkCompile.maxSize"的值改小，"hvigor.enableMemoryCache"改为false后，可能会导致编译时长增加，请耐心等待。
    

*   如果上述修改未能达到预期效果，可以尝试使用非并行模式执行编译。
    
    *   在菜单栏中依次点击“File > Settings > Build, Execution, Deployment > Build Tools > Hvigor”，取消勾选“Execute tasks in parallel mode”。
        
        ![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/86/v3/qOwd0op0Q2momrzVU2gh7Q/zh-cn_image_0000002229758673.png?HW-CC-KV=V1&HW-CC-Date=20260612T074812Z&HW-CC-Expire=86400&HW-CC-Sign=1942F242E5E4EA69E69985356CC845E2B3A81580206E50B2546329854DA3C184)
        
    *   在命令行最后添加--no-parallel，示例：
        
        hvigorw assembleHap --no-parallel
        
    
    ![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/7f/v3/T3_I_BNPTqaA7hq_92F98A/note_3.0-zh-cn.png?HW-CC-KV=V1&HW-CC-Date=20260612T074812Z&HW-CC-Expire=86400&HW-CC-Sign=19A3D26A952FCECC41489C0177F2A3D729B54633AE5BAF74548D974616D640EA)
    
    使用非并行模式编译，内存占用将减少，但编译时间会延长，请耐心等待。