mobx-quick-tree
is designed to be fast, so, we have some benchmarks set up to help understand how fast it really is in the bench
folder!
You can run a benchmark file with pnpm x <the file>
:
pnpm x bench/instantiation.benchmark.ts
This will run the file and output a speed measurement for comparison between git branches.
You can also run all the benchmarks with:
pnpm x bench/all.ts
It's nice to use the benchmarks for profiling to identify optimization candidates.
The benchmark framework supports a --profile
option for writing a profile of the benchmark loop, excluding setup and teardown code. Run a benchmark with profile, then open the created .cpuprofile
file:
pnpm x bench/instantiation.benchmark.ts --profile
You can also run a benchmark to generate a profile using node.js' built in sampling profiler
node -r ts-node/register/transpile-only --prof bench/create-large-root.ts
node --prof-process isolate-*.log
You can postprocess the generated isolate-0x<something>.log
file into the data flamegraph
expects, and then feed it to flamegraph
to see a visual breakdown of performance. You can do that in one command like so:
node --prof-process --preprocess -j isolate-*.log | pnpm flamebearer
You can also use the profiler built into VSCode for executing scripts and profiling them. There's an example launch.json
task in launch.json
for running a script. You can also use console.profile()
and console.profileEnd()
to programmatically start a CPU profile in a benchmark while working on it.
deoptigate
is a powerful tool for analyzing how compliant with V8's optimizations our code is. Run a script through deoptigate by first building the TS into JS with pnpm build
, then run deoptigate on the script:
pnpm build
pnpm deoptigate dist/bench/create-many-model-class.js