Appearance
The profiler
Which lines of your script take its time? Turn on Profiler mode in the Script Editor's More menu. The script runs again with every line measured, and the editor's gutter shows each line's share of the run, with the three costliest lines marked.
The profiler works on Pine Script and AmenoScript alike, and on any of the four engines.
Turning it on
- Open the script in the Script Editor.
- Choose More, then Profiler mode. The script is profiled at once.
- Read the gutter: each line's share of the run, and behind it a bar of that size.
- Open the Profile panel at the bottom of the editor for the rest: the engine, the views and the options.
Edit the script and press Profile again to measure the new version. Choose Profiler mode again to turn it off.
Reading a line
A line shows its share of the run, its time including everything it calls, and how many times it ran, on all bars and on the last bar.
- A block header carries its whole block: an
if,for,whileorswitch, and a declaration whose value is aniforswitch. Its own time, spent stepping a loop or testing a condition, shows apart from the lines inside it. - A function's body lines add up every call, while a call site shows only its own call.
- A
request.*line shows its context, the bars it ran on and its time, including a request inside a function. - Function headers,
elselines, comments and continuation lines show nothing. - A library's lines report in the library's own text.
- What no line holds, such as each bar's setup and plotting, has a row of its own.
The views
| View | Shows |
|---|---|
| Lines | Each line's share, time and executions, as in the gutter. |
| Hints | What the measurements suggest you change. |
| Calls | The call tree, by call path. |
| Bars | What each bar cost, with the costliest bars listed. |
| Requests | Each request.* site's context, bars and time, and for pairs their steps. |
| Drawings | For each line that draws: how many it made, deleted, kept and showed. |
| Engine | Where the engine itself spent the run, phase by phase. |
| Ticks | A live bar's tick, when you measure ticks. |
Hints come only from what the run measured. They flag drawings that never show, table cells written on bars nobody sees, a block that runs every bar while its drawings don't survive it, two requests on one context, and a slow engine path.
Engines and options
The panel's Engine menu picks the engine to profile on: Interpreter, JIT, Rust walker or Rust native. A profile starts on the engine the chart runs the script on: Rust native for most scripts, and the JIT for one the chart keeps in your browser, as Which engine runs where lists. Each engine's run time shows beside its name once it has run, so you can compare them.
The Profile options menu sets what to measure:
| Option | Measures |
|---|---|
| Lines | Each line. The default. |
| Lines and builtins | Each line, plus each builtin call by name and site: its calls and its time per call. |
| Repeat 5 times | The median of five runs, which steadies the figures. |
| 20 ticks on the last bar | Twenty moves of the last bar's close, as a live chart's ticks, with each tick's time. |
Pin as baseline keeps the current profile so the next one shows the change. Export JSON saves the profile, and Copy for an agent copies it as text with line numbers.
How far to trust the figures
- Counts are exact. All four engines number the statements the same way, so their counts on a line must agree. A line where two engines' counts differ shows an engine bug.
- Times on the interpreter and the walker are measured, with the profiler's own cost taken off each line.
- Times on the JIT and Rust native are sampled. Reading a clock costs compiled code more than most statements, so a sampler looks at what is running about once a microsecond. A line under 30 samples is marked
?, too few to trust. - Two engines' shares can differ a lot, because each spends where the other doesn't. Compare a line's share across edits on one engine, not across engines.
- A profiled run is slower than a plain one, and the head of the profile says by how much. A run without the profiler pays almost nothing for it.