skip to Main Content

I’m using Visual Studio Code (VSCode) for a bigger project where we have around 10 to 15 sub git projects in one workspace.

All these projects are Typescript so I use tasks.json + vscode Option Tasks: Manage Automatic Tasks in Folder.

This leads to 10-15 nodes processes with each using around 1-4% CPU usage. Unfortunately I have multiple work spaces open so I end up having a lot of node processes not just only consuming my memory also my cpu.

It heats up my pc and I want to know if this can be prevented. 

Some projects I change often (2-3) and some are always on master and I barley never touch them. Do you have any best practices how to overcome this problem?

My problem in screen: my screen

My code --status (snippet):

CPU %   Mem MB     PID  Process
1      197   28044  code main
1     1114   28046     gpu-process
0        0   28048     utility
0     1442   28051     window (textarea.vue — d-reporting-vue-ws)
...
15       66   97382           electron_node cli.js 
0      328   28391       extensionHost
0       66   30325         electron_node tsserver.js 
0      721   30327         electron_node tsserver.js 
0       66   30358           electron_node typingsInstaller.js typesMap.js 
0      393   30361         /nvm/versions/node/v12.16.3/bin/node //.vscode/extensions/dbaeumer.vscode-eslint-2.1.8/server/out/eslintServer.js --node-ipc --clientProcessId=28391
0        0   97363         electron_node ms-vscode.js bundle.js 
0        0   28947       watcherService
1        0   31594       node ...-reporting-ws/w-articleloader/node_modules/.bin/tsc -p ...-reporting-ws/w-articleloader/tsconfig.json --watch
2        0   31596       node ...-reporting-ws/w-api-redis/node_modules/.bin/tsc -p ...-reporting-ws/w-api-redis/tsconfig.json --watch
2        0   31598       node ...-reporting-ws/w-api-i18n/node_modules/.bin/tsc -p ...-reporting-ws/w-api-i18n/tsconfig.json --watch
2        0   31599       node ...-reporting-ws/w-api-elasticsearch/node_modules/.bin/tsc -p ...-reporting-ws/w-api-elasticsearch/tsconfig.json --watch
1        0   31600       node ...-reporting-ws/w-api-db/node_modules/.bin/tsc -p ...-reporting-ws/w-api-db/tsconfig.json --watch
4        0   31601       node ...-reporting-ws/d-lib-hb/node_modules/.bin/tsc -p ...-reporting-ws/d-lib-hb/tsconfig.json --watch
3      197   31603       node ...-reporting-ws/node_modules/.bin/tsc -p ...-reporting-ws/d-reporting-hb/tsconfig.json --watch
3        0   31604       node ...-reporting-ws/w-resource-manager/node_modules/.bin/tsc -p ...-reporting-ws/w-resource-manager/tsconfig.json --watch
1        0   31605       node ...-reporting-ws/w-logger-winston/node_modules/.bin/tsc -p ...-reporting-ws/w-logger-winston/tsconfig.json --watch
3        0   31607       node ...-reporting-ws/w-mailer/node_modules/.bin/tsc -p ...-reporting-ws/w-mailer/tsconfig.json --watch
2        0   31608       node ...-reporting-ws/w-core/node_modules/.bin/tsc -p ...-reporting-ws/w-core/tsconfig.json --watch
1        0   31609       node ...-reporting-ws/w-base-types/node_modules/.bin/tsc -p ...-reporting-ws/w-base-types/tsconfig.json --watch
2        0   31610       node ...-reporting-ws/w-fulfillment-lib/node_modules/.bin/tsc -p ...-reporting-ws/w-fulfillment-lib/tsconfig.json --watch
3        0   31612       node ...-reporting-ws/w-rm-type-pug/node_modules/.bin/tsc -p ...-reporting-ws/w-rm-type-pug/tsconfig.json --watch
2        0   31615       node ...-reporting-ws/w-database-abstraction-couchdb/node_modules/.bin/tsc -p ...-reporting-ws/w-database-abstraction-couchdb/tsconfig.json --watch
2        0   31737       node ...-reporting-ws/w6-compatibility/node_modules/.bin/tsc -p ...-reporting-ws/w6-compatibility/tsconfig.json --watch
1        0   31738       node ...-reporting-ws/w-number-group/node_modules/.bin/tsc -p ...-reporting-ws/w-number-group/tsconfig.json --watch

My tsconfig

{
"compilerOptions": {
    "target": "ES2016",
    "module": "CommonJS",
    "moduleResolution": "Node",
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "rootDir": "src",
    "outDir": "./",
    "sourceMap": true,
    "declaration": true,
    "strict": true,
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "removeComments": true,
    "pretty": true,
    "forceConsistentCasingInFileNames": true,
    "allowJs": true,
    "baseUrl": ".",
    "paths": {
        "*": ["types/*"]
    }
},
"include": [
    "src"
],
"exclude": [
    "node_modules"
]}

Finally my task.json (snippet)

{
        "type": "typescript",
        "tsconfig": "d-lib-hb/tsconfig.json",
        "option": "watch",
        "problemMatcher": [
            "$tsc-watch"
        ],
        "runOptions": {
            "runOn": "folderOpen"
        }
    }

2

Answers


  1. Chosen as BEST ANSWER

    I found a solution on accident because I tried to reduce the amount of tasks but what about reducing the impact of each task?

    Solution

    Set the environment variable

    TSC_NONPOLLING_WATCHER="1" 
    

    In my case i had to adjust .zprofile via

    export TSC_NONPOLLING_WATCHER="1"
    

    The difference is perfectly explained here: https://medium.com/@julioromano/writing-typescript-on-a-laptop-this-might-improve-your-battery-life-f503dd16f019

    I even could help another person with the same problem he had 2 years ago: Does tsc-watch consume TSC_NONPOLLING_WATCHER?

    All in all im really pleased and my laptop is quite and calm (2-5% usage instead of 30%).


  2. Although it reduces so much of the RAM|CPU usage but you can also reduce the amount of resource used by vscode for larger project by excluding some of the unimportant & hardly touched folders/projects e.g:node_modules, .vscode, git etc…

    Read this medium article about doing this, I wrote that… Hope it helps you even a little bit…

    Make Visual Studio Code Less RAM Consuming & Faster

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search