kite-cli icon indicating copy to clipboard operation
kite-cli copied to clipboard

`kite alerts create` and `modify` load the instrument master twice when `--lhs` and `--rhs` are both instruments

Open jay-tau opened this issue 1 week ago • 0 comments

Summary

kite alerts create and kite alerts modify load the instrument master twice when both --lhs and --rhs name instruments, such as NSE:INFY and NSE:TCS. With --lhs and a fixed --value they load it once. In the dry runs below, the two-instrument commands took nearly twice as long.

Steps to reproduce

I ran the kite release binary built at 1162630 offline, in a network namespace with only loopback. The cache held a fresh, synthetic instrument master of 120,000 rows (39 MB), so nothing was downloaded, and a local mock served GET /alerts/:uuid for modify. Every run was a dry run.

strace -f -e trace=openat kite --json alerts create --name demo --lhs NSE:INFY --operator '>=' --rhs NSE:TCS

Expected

instruments.json is opened once, as it is for --lhs with --value.

Actual

Command instruments.json opened Median of 10 runs
alerts create … --lhs NSE:INFY --rhs NSE:TCS 2 0.55 s
alerts create … --lhs NSE:INFY --value 1600 1 0.29 s
alerts modify UUID --lhs NSE:INFY --rhs NSE:TCS 2 0.57 s
alerts modify UUID --lhs NSE:INFY --value 1600 1 0.29 s

With a 300,000-row (98 MB) synthetic master, the medians were 1.46–1.47 s with --rhs and 0.76–0.77 s with --value.

Cause

params resolves --lhs and --rhs through resolve_instrument, and each call runs instruments::load, which parses the cached master and builds its index again. params runs before the dry-run check, so a dry run pays for both loads. If refreshing a stale cache produces a fresh, usable file, the second load parses that file again.

The alert tests that seed the cache (cache_alert_instruments) check the form that is built, not how many times the master is loaded.

I found this against a local mock server only, not a live account.

jay-tau avatar Nov 23 '26 17:11 jay-tau