function
jsc.profile
callback: T,
sampleInterval?: number,
...args: Parameters<T>
Runs JavaScriptCore's sampling profiler on a function and returns the profile.
The profiler records the JavaScript stack every sampleInterval microseconds while callback runs, then stops. The profile summarizes where the samples landed; see SamplingProfile. If callback throws, the profiler stops and the exception propagates.
Tier names in the output:
- LLInt ("Low Level Interpreter") is the interpreter that runs before any JIT compilation
- Baseline is the first JIT compilation tier: the least optimized, but the fastest to compile
- DFG ("Data Flow Graph") is the second JIT compilation tier: some optimizations, but slower to compile
- FTL ("Faster Than Light") is the third JIT compilation tier: the most optimizations, but the slowest to compile
@param callback
The function to profile. It is called immediately, with args.
@param sampleInterval
How often to sample the stack, in microseconds. Defaults to 1000 (once a millisecond).
@param args
Arguments to call callback with
@returns
The profile. If callback returns a promise, profiling continues until that promise settles, and a promise of the profile is returned instead.
import { profile } from "bun:jsc";
const { functions } = profile(() => JSON.parse(JSON.stringify(bigObject)), 100);
console.log(functions);