Skip to content

多页面开发时的性能问题 #3838

Closed
@nashaofu

Description

@nashaofu

Version

3.6.3

Environment info

  System:
    OS: macOS 10.14.4
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
  Binaries:
    Node: 10.15.3 - ~/.nvm/versions/node/v10.15.3/bin/node
    Yarn: 1.15.2 - ~/.nvm/versions/node/v10.15.3/bin/yarn
    npm: 6.9.0 - ~/.nvm/versions/node/v10.15.3/bin/npm
  Browsers:
    Chrome: 73.0.3683.103
    Firefox: Not Found
    Safari: 12.1
  npmPackages:
    @vue/babel-helper-vue-jsx-merge-props:  1.0.0-beta.3 
    @vue/babel-plugin-transform-vue-jsx:  1.0.0-beta.3 
    @vue/babel-preset-app:  3.5.5 
    @vue/babel-preset-jsx:  1.0.0-beta.3 
    @vue/babel-sugar-functional-vue:  1.0.0-beta.3 
    @vue/babel-sugar-inject-h:  1.0.0-beta.3 
    @vue/babel-sugar-v-model:  1.0.0-beta.3 
    @vue/babel-sugar-v-on:  1.0.0-beta.3 
    @vue/cli-overlay:  3.5.1 
    @vue/cli-plugin-babel: ^3.2.0 => 3.5.5 
    @vue/cli-plugin-eslint: ^3.2.0 => 3.5.1 
    @vue/cli-service: ^3.2.0 => 3.5.3 
    @vue/cli-shared-utils:  3.5.1 
    @vue/component-compiler-utils:  2.6.0 
    @vue/eslint-config-standard: ^4.0.0 => 4.0.0 
    @vue/preload-webpack-plugin:  1.1.0 
    @vue/web-component-wrapper:  1.2.0 
    babel-helper-vue-jsx-merge-props:  2.0.3 
    eslint-plugin-vue: ^5.0.0-0 => 5.1.0 
    vue: ^2.5.17 => 2.5.21 
    vue-eslint-parser:  4.0.3 
    vue-hot-reload-api:  2.3.3 
    vue-loader:  15.7.0 
    vue-router: ^3.0.1 => 3.0.2 
    vue-style-loader:  4.1.2 
    vue-template-compiler: ^2.5.17 => 2.5.21 
    vue-template-es2015-compiler:  1.9.1 
    vuex: ^3.0.1 => 3.0.1 
  npmGlobalPackages:
    @vue/cli: 3.6.2

Steps to reproduce

把一个单页面项目修改为多页面,即复制入口文件和模板文件,然后在vue.config.js中的pages字段添加模板和入口。根据项目大小的不同,会存在添加7个页面后,修改文件重新编译的时候node内存溢出,即webpack进程运行的内存超过node默认分配的内存大小导致进程结束。在单页面的时候也存在性能问题,特别是修改入口文件的时候,编译速度非常慢。

<--- Last few GCs --->
io[86760:0x10284b000]   331522 ms: Mark-sweep 1403.5 (1429.1) -> 1403.4 (1430.6) MB, 392.4 / 0.0 ms  (  16.8 ms in 16 steps since start of marking,
 biggest step 7.8 ms, walltime since start of marking 413 ms) (average mu = 0.146, current mu = 0.014) allocat[86760:0x10284b000]   331955 ms: Mark
-sweep 1404.5 (1430.6) -> 1404.3 (1431.1) MB, 412.1 / 0.0 ms  (  17.9 ms in 17 steps since start of marking, biggest step 6.2 ms, walltime since st
art of marking 433 ms) (average mu = 0.083, current mu = 0.009) allocat

<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 0x28fbee7cfc7d]
    1: StubFrame [pc: 0x28fbee7d0fea]
    2: StubFrame [pc: 0x28fbee7c69e2]
Security context: 0x02cce911d9d1 <JSObject>

What is expected?

经过我这边测试,导致以上问题的主要原因是在开发的是后没有使用webpack的optimization.splitChunks配置来分包,每个入口都是完整编译所有文件,不能共享node_modules下的编译文件,所以导致内存不足。单页面的时候,修改入口文件也会重新编译node_modules下面的文件,所以速度较慢。

What is actually happening?

在开发模式下添加webpack的optimization.splitChunks配置

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions