Soon available

Not on the Chrome Web Store yet

ProRealCode Studio is on its way. As soon as it is published, this button will take you straight to its Chrome Web Store page.

Chapter 11 · Part II — Writing code

Find the line that slows your chart.

Every code on the chart costs time at each update of the price. Studio shows that time next to each code, and one click further, which of its lines spends it. A slow chart then becomes one line to rewrite.

  1. 01The chip What one update of a code costs.
  2. 02Hot lines The six costliest lines of a code.
  3. 03Timings on the flow map The same measure, card by card.
  4. 04What makes a code slow The usual causes, and what to try.
Two rows of the Codes on the chart window. On the second, Trend heat ribbon + regime HUD, a red chip with a lightning bolt reads 66.5 ms; the pointer on it has opened the tooltip “last rebuild: 66.5 ms over 3000 bars · click to profile this code line by line”.
The chip of “Trend heat ribbon + regime HUD”, and its tooltip.
Before you startThe code you want to measure is on the chart (chapter 02). The chips live in the window “Codes on the chart”: open it with Alt + I (chapter 12).
ProRealCode StudioUser guide · Chapter 11
01 · The chip

One number per code: what one update costs.

The performance chip ⚡ 66.5 ms on the row of Trend heat ribbon + regime HUD, with its tooltip open above it. 1 2
The row of a code in “Codes on the chart”.
  1. The chip. Once the chart has updated, the time of one update of this code. Before that, the time of its last full calculation.
  2. The tooltip. Point at the chip: “last rebuild: 66.5 ms over 3000 bars”, then, when known, the time of one update (“steady tick”), of a full calculation, and per bar.
The chip readsWhat it means
—Not measured yet.
2.1 ms, plainUnder 16 ms. Nothing to do.
⚡ 23 ms, amberFrom 16 ms. Worth a look if the chart feels slow.
⚡ 66.5 ms, redFrom 50 ms. Each update holds the page long enough to feel stuck.

Very small times read in µs or ns. The numbers in the first three rows are examples.

  1. Press Alt + I.“Codes on the chart” opens. Each row carries its chip, left of the row's buttons.
  2. Look for amber and red.When the codes cost 16 ms or more together, the status line of the editor adds the total, for instance “⚡ 70 ms engine”.
  3. Click a red chip.Its Hot lines open under the row (sheet 3).
ProRealCode StudioUser guide · Chapter 11
02 · Hot lines

Click the chip, and the costliest lines line up.

Hot lines under the row of Trend heat ribbon + regime HUD: the heading “Hot lines — 3000 bars, 145 ms attributed”, six bars for lines 45, 42, 57, 53, 41 and 141 with 11 %, 7 %, 6 %, 5 %, 5 % and 4 %, the first one red, and the footnote “Measured with per-line timers — compare the lines to each other, not to the chip above.” 1 2 3 4
Hot lines of “Trend heat ribbon + regime HUD”, on 3,000 bars.
  1. The chip you clicked. Click it again to close the table.
  2. The heading. How many bars, and how much time the lines below share.
  3. The costliest line, in red. Each bar is measured against it; the percentage is the line's share of the time.
  4. The footnote. Timing every line slows the code down, so these times run higher than the chip. Compare the lines with each other.
  1. Point at a line of the table.The tooltip says how many times it ran and how long it took on its own.
  2. Click it.The editor opens on that line. Its number in the margin is marked as the hot line.
  3. Rewrite the line, click “Run”, then click the chip again.The table is measured again each time you open it. Nothing is measured in the background.
A loop shows its inside lineThe time of a FOR loop is charged to the line inside it that does the work, the one you would change. A table that reads “Too cheap to attribute — nothing here is slowing the chart.” means the code is not your problem.
ProRealCode StudioUser guide · Chapter 11
03 · Timings on the flow map

The same measure, spread over the cards of the map.

Hot lines give six line numbers. The flow map (chapter 10) puts a share of the time on every card, so you see which part of the calculation costs, and what it feeds.

The search field of the map, “48 of 62 shown”, then “168 ms profiled over 3,000 bars”.
With “Show timings” on, the total appears beside the search field.
Cards of the map, each with a small percentage badge: 24 % on each Ribbon ema step, 1 % to 9 % on settings and values, 13 % on COLORBETWEEN ×4.
Each card carries its share: here 24 % on each “Ribbon ema” step, 13 % on “COLORBETWEEN ×4”.
  1. Run the code, then open its map: ⋯ › “Dataflow map”.The code must be on the chart: otherwise the map says “Put this code on the chart (▶ Run) and the timings become measurable.”
  2. Click “Show timings”.The badges appear, and the total beside the search field. Once the chart has updated, it adds what the chart pays per update.
  3. Click the card with the largest share.Its panel repeats the share and shows its code (chapter 10, sheet 4).
ProRealCode StudioUser guide · Chapter 11
04 · What makes a code slow

A few habits cost far more than they seem to.

CalculateOnLastBars: fast once, slow at every new candle

DEFPARAM CalculateOnLastBars = N limits the first calculation to the last N bars. It caps nothing when the chart holds N bars or fewer. And each new candle moves the window, so the whole window is calculated again.

151 → 14 msfirst calculation
0.09 → 12.4 mseach new candle
11new candles, and the saving is spent

Measured on 6,000 bars with a window of 500, which also left the bars before the window blank. Leave it out, unless the chart holds far more history than your code needs.

Loops run on every bar

A FOR loop of 50 turns on a chart of 3,000 bars runs its inside line 150,000 times. Hot lines puts that line at the top: fewer turns is time saved on every bar.

“rebuilds in full every update”

When the chip's tooltip ends with this, the code recalculates its whole history at each update. It names why.

The tooltip namesWhere it comes from
TIMEFRAME segments on another instrument in default modeA TIMEFRAME block that reads another instrument.
this indicator's own TIMEFRAME / instrument settingA timeframe or instrument chosen in ⚙ Settings, not in the code (chapter 08).
an expression evaluated on another instrumentA value read from another instrument.
repainting series (ZigZag…)An instruction whose past values change with new bars.
CALL "name" → repainting seriesThe same, inside a code this one calls.

Each code on the chart adds its own time. ⚙ Preferences › Limits › “Maximum codes on the chart” caps how many run at once: 8 by default.

ProRealCode StudioUser guide · Chapter 11
Chapter 11 · In short

Red chip, Hot lines, one line to rewrite.

WhereWhat it tells you
The chipWhat one update of each code costs. Amber from 16 ms, red from 50 ms.
Hot linesThe six lines that spend the most, as shares. Click one to edit it.
Show timingsThe same shares on the cards of the flow map.

Hot lines add up to more than the chip. Which is right?

The chip. Timing every line slows the code down, so read Hot lines as shares, not as times.

The chip reads “—”.

The code has not been measured yet. Wait for the next update of the chart, or run it again.

My code is fast, but the chart is slow.

Look at the other rows: each code adds its time, and the status line gives the total.

Problems says “computing for 25 s”.

A first calculation past 20 seconds. The chart keeps its last drawing until it lands (chapter 09).

Does measuring slow my chart?

Only at the moment you open Hot lines or “Show timings”: the code is calculated once more. The chip itself costs nothing.

Can I see the lines of a code shared with me?

No. You never see its source, so there is nothing to show line by line (chapter 22).

Next

Chapter 12 · Codes on the chart

Show, hide, place and remove the codes running on your chart.

ProRealCode StudioUser guide · Chapter 11
ProRealCode ProRealCode
Loading...