Implements a profiler for VM execution and the garbage collector.
This profiler collects and prints execution time per VM instruction, and a frequency and stopping duration of GC.
Using --profile option enables this feature.
$ cargo run --release examples/fibo.js --profile
Compiling rapidus v0.1.1
Finished release [optimized] target(s) in 1m 23s
Running `target/release/rapidus examples/fibo.js --profile`
# performance analysis
total execution time 13484 microsecs gc time 1288 microsecs
Inst total % ave.time / inst
PushInt8 8.02 % 219.38 nanosecs
Add 1.25 % 171.36 nanosecs
Sub 1.58 % 108.34 nanosecs
Lt 2.10 % 143.54 nanosecs
JmpIfFalse 1.65 % 113.08 nanosecs
Call 48.87 % 3339.68 nanosecs
Return 8.30 % 567.20 nanosecs
Pop 0.00 % 218.00 nanosecs
GetValue 18.68 % 425.65 nanosecs
# GC performance
State count total time
Init 300 0.00 millisecs
Mark 1473 0.00 millisecs
Sweep 200 0.00 millisecs
Function id becomes to be generated by Factory as new FunctionId type.
Some codes using deprecated syntax were fixed.
The frequency of GC was reduced to 1/100, because the GC consumed too much time previously.
The dependency on LLVM was removed temporally.
VM#compile() returns UserFunctionInfo instead of FunctionInfo, and generate module id automatically. This refactoring simplifies the code for VM execution.
/// before
let mut vm = vm::vm::VM::new();
let mut parser = parser::Parser::new("test", text);
let node = parser.parse_all().unwrap();
let mut iseq = vec![];
let main_id = vm.factory.main_func_id();
let func_info = vm.compile(&node, &mut iseq, true, main_id).unwrap();
vm.run_global(func_info, iseq).unwrap();
/// after
let mut vm = vm::vm::VM::new();
let mut parser = parser::Parser::new("test", text);
let node = parser.parse_all().unwrap();
let user_func_info = vm.compile(&node, true).unwrap();
vm.run_global(user_func_info).unwrap();
This PR:
--profile
option enables this feature.Factory
as newFunctionId
type.VM#compile() returns UserFunctionInfo instead of FunctionInfo, and generate module id automatically. This refactoring simplifies the code for VM execution.
Thank you for reading this!