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

**问题现象**

编译构建时，内存或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/fe/v3/WAYtpQ5FR9ia2fNiAhS1MA/note_3.0-zh-cn.png?HW-CC-KV=V1&HW-CC-Date=20260709T134355Z&HW-CC-Expire=86400&HW-CC-Sign=422276B75F9CB62B7E098867DDF4465C35E7CD0EC8540680C80D3E45278AAC51)
    
    当配置项"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/25/v3/8LyUXw-kQ72Pp5ZhQ6BCLg/zh-cn_image_0000002624638446.png?HW-CC-KV=V1&HW-CC-Date=20260709T134355Z&HW-CC-Expire=86400&HW-CC-Sign=7C7086FF513752EFE6230D864B1282FA38F10A56743F4265E107D37771E11EFE)
        
    *   在命令行最后添加--no-parallel，示例：
        
        hvigorw assembleHap --no-parallel
        
    
    ![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/9e/v3/IpwohO8pQXib1wFL_WYxJg/note_3.0-zh-cn.png?HW-CC-KV=V1&HW-CC-Date=20260709T134355Z&HW-CC-Expire=86400&HW-CC-Sign=C9CB6856369A01780B46C6BB69F6DCD485571D9B0BABD07AB5FF7282CFE11B41)
    
    使用非并行模式编译，内存占用将减少，但编译时间会延长，请耐心等待。