1.清除多余包
npm prune --production
2.使用代码优化
a.grunt-contrib-uglify,精简代码
b.去掉所有console.*
c.使用grunt-contrib-jshint检测代码
3.尽可能使用strict mode
文件中使用'use strict'或者命令node --use_strict
4.内存优化、垃圾回收 v8-options
64位V8是1.5G内存上限,32位0.7G,通过下面参数可以修改
--max_new_space_size (max size of the new generation (in kBytes))
type: int default: 0
--max_old_space_size (max size of the old generation (in Mbytes))
type: int default: 0
--max_executable_size (max size of executable memory (in Mbytes))
type: int default: 0
--gc_global (always perform global GCs)
type: bool default: false
--gc_interval (garbage collect after <n> allocations)
type: int default: -1
node --use_strict --max_old_space_size=2000 --max_executable_size=2000 --gc_global --gc_interval=200 app.js