Higher-timeframe scripts now run in a fraction of the time
request.security used to be the slowest part of a PyneCore backtest. A script that pulls in a few other timeframes or symbols could spend most of its run time on them. Over the last two releases we have taken that cost apart piece by piece, and on the scripts we test against, most of it is gone.
Each request.security call is computed in its own background process running alongside the chart. Until now, that process ran the entire script on every bar just to produce its one value. Now it runs only the lines that value depends on. Calls that read the same data share one process instead of starting one each. A value that cannot change before the higher-timeframe bar closes, such as the previous day’s close, is now computed once per period rather than again on every chart bar.
On one script from our test corpus, a run went from 91 seconds to 20. The previous release had already cut another script from 126 seconds to 9. The results did not change: on the scripts we tested, the output is identical, bar for bar.