babel / parser_performance

13 stars 16 forks source link

parser_performance

Parses various fixtures and outputs parse times over various iterations

Run

build a production release of babel-parser

cd babel
NODE_ENV=production BABEL_ENV=production gulp build-rollup

Run parser performance

It is recommended to clone parser_performance next to babel repository

git clone git@github.com:babel/parser_performance.git
yarn
PARSER_ALL=1 yarn run test // performance test
yarn run memory // memory usage test

Performance PRs

Check the performance label in the babel repo for some examples.

Performance Test

# Run performance test with all fixtures on local babel build
yarn run test

# Run performance test on ember.js fixture and compared to baseline babel parser
FILE=ember PARSER=babel,dev yarn run test

# Run performance test on all parsers and all files
PARSER_ALL=1 yarn run test

# Specify a custom babel parser path and run performance test on all files
BABEL_PARSER_PATH=relative/path/from/parser_performance/to/babel-parser yarn run test

Perf Tips

Microbenchmarks don't help that much, should test the real thing? (Also I don't know what I'm talking about)

Checking Performance

Install/Use Node 12

nvm use 12
node -v

Install NIM

https://chrome.google.com/webstore/detail/nodejs-v8-inspector-manag/gnhhdgbaldcilmgcpfddgdbkhjohddkj?hl=en

It's a chrome Extension that helps automatically open the devtools when running --inspect

Use node --prof

https://nodejs.org/en/docs/guides/simple-profiling/

node --prof script.js
node --prof-process isolate*.log
# node --prof-process isolate*.log > out.txt

With @babel/parser:

node --prof ./node_modules/@babel/parser/bin/babel-parser.js fixtures/es5/ember.debug.js > /dev/null
node --prof-process isolate*.log

Use npm run cpu-prof

Node.js 12 introduces --cpu-prof to starts V8 CPU Profiler on start up.

# Generate CPU Profile running dev parser on ember,
# This command will output a cpu profile inside the ./cpuprofile directory, i.e. `CPU.20190906.174010.51327.0.001.cpuprofile`
PARSER=dev FILE=ember npm run cpu-prof

Load generated cpu profile to Chrome Devtools, and analyze the performance recording.

Use node --trace-opt

node --trace-opt script.js | grep myFunc
node --trace-opt ./node_modules/@babel/parser/bin/babel-parser.js fixtures/es5/ember.debug.js

Use node --inspect-brk

https://medium.com/@paul_irish/debugging-node-js-nightlies-with-chrome-devtools-7c4a1b95ae27

Point node to the @babel/parser script and pass in a file to parse

In this case I am running node in parser with parser_performance/ in sibling folder

cd parser

# node --inspect-brk script.js
node --inspect-brk ./bin/babel-parser.js ../parser_performance/fixtures/es5/angular.js

If you have install NIM, it should open up chrome and show this view: (if not you can open the url shown in the console yourself)

Imgur

Then click on the "Profiler" Tab

Imgur

Then click "Start"

Imgur

Wait a little bit and click "Stop", and you will be redirect to this screen

Imgur

Use npm run print-bytecode

# Use develop babel to parse material-ui-core fixture, output the bytecode
# generated by ignition interpreter to `parse.bytecode`
FILE=material npm run print-bytecode

# Specify `PARSER` to use baseline babel or other parsers
FILE=material PARSER=babel npm run print-bytecode

User npm run print-code

# Use develop babel to parse material-ui-core fixture, output the optimized dissembly code
# generated by turbofan compiler to `parse.asm`
FILE=material npm run print-code

Some Links