Spaces:
Running
Download docs/performance.md from Arrechenash/stocks: direct link, hf CLI and curl.
- Browser
- Download file 6.73 kB
-
https://huggingface.co/spaces/Arrechenash/stocks/resolve/main/docs/performance.md
- Command line
-
hf download hf://spaces/Arrechenash/stocks/docs/performance.md
-
curl -L -o performance.md https://huggingface.co/spaces/Arrechenash/stocks/resolve/main/docs/performance.md
Performance
LT tracks wall-clock performance through a serial benchmark suite (tests/perf/,
run with make perf-benchmark) plus a baseline comparison gate (make perf-check).
Frontend timing on /discover comes from instrumentation already in the page.
This document records where each number lives, how to re-check it, and what the
gates decide on.
1. Frontend: /discover page timings
static/js/features/discover/discover-page.ts instruments every Discover fetch
with emitDiscoverPerformance(stage, startedAt, requestSeq). Stages:
fetch:startβ request begins, AbortController createdflagsβ symbol flags loaded (cached after the first call)watchlistβ watchlist state refreshed (skipped on background polls)screenerβ/api/screenerresponse committedprimary-renderβ table rendered afterapplyDiscoverWave
Each stage is pushed onto window.__discoverPerformance (capped at 100 entries),
dispatched as a discover-performance CustomEvent, and recorded with
performance.measure("discover:<stage>", {start, end, detail}).
Re-check in DevTools on /discover:
window.__discoverPerformance; // [{stage, durationMs, requestSeq}]
performance.getEntriesByName("discover:screener");
[...document.querySelectorAll(".stock-row--list")].length; // rows painted
Charts-mode request counts: open the page, wait for
#table-container .stock-row, click
#discover-view-toggle .view-btn[data-mode="charts"], wait, then read
performance.getEntriesByType("resource") and count by path. A scratch copy in
/tmp is enough; it does not belong in the repo.
Backend bounds for one Discover warm:
/api/screenerposts withlimit: 50; one warm is at most 60 Finviz/stockrequests (GROUP_WARM_LIMIT = 60, also the backend's default warm limit inDiscoverDescriptionWarmRequestincore/domain/schemas.py). Rows past 60 are described by the next group run, not by this press./api/discover/patternsgroups the universe rows (min_supportfromGROUP_MIN_SUPPORT). The response cache key hashes only the stable row fields (_PATTERN_ROW_FIELDS,modules/discover/routes.py) plus a digest of the described descriptions; TTL is_PATTERN_CACHE_TTL = 300seconds. Volatile quote/timestamp fields are intentionally excluded so an unrelated quote change does not fragment the cache./api/discover/descriptions/warmpopulates the description cache: one Finviz request per symbol, bounded bymin(req.limit, DISCOVER_DESCRIPTIONS.max_symbols), run under a semaphore so a hundred concurrent scrapes cannot rate-limit the whole provider. Symbols already cached are counted as cached, not refetched. The warm is keyed on session|sorted symbol list, so re-running the same universe does not spend the provider twice.- Webull fallback cache key is
webull_fallback_{session}_{direction}.json; session/direction are validated withplain_token, so they can never reach the filesystem outside the cache directory.
2. Backend benchmark suite
tests/perf/ holds the serial perf suite, every file marked pytest.mark.perf.
make test deselects it (-m "not e2e and not perf") because a wall-clock
number under pytest -n auto measures the scheduler as much as the code.
Commands:
make perf-benchmark # serial run, writes tests/perf/latest.json
make perf-check # compares latest.json against tests/perf/baseline.json
make perf-benchmark runs pytest tests/perf/ --benchmark-json=tests/perf/latest.json.
make perf-check runs that suite, then compares each benchmark's mean against
tests/perf/baseline.json with LIMIT = 1.20 (20% over baseline fails).
Gate rules (scripts/perf_check.py):
- Decides on the mean. Percentiles move with round count and are only for reporting and for the p95 target (a measured figure, not pass/fail).
- A baseline entry with no benchmark behind it is reported as stale and does not fail. A benchmark with no baseline entry is unbaselined: its numbers print without a ratio.
Baseline (tests/perf/baseline.json, committed):
| benchmark | mean |
|---|---|
test_get_candidates_benchmark[gap-volume] |
0.4546 s |
test_get_candidates_benchmark[relative-volume] |
0.3510 s |
test_compile_benchmark |
4.55e-05 s |
Other serial budget files:
tests/perf/test_scan_stage_budget.pyβ scan-stage gate (core/dsl,ScanService,enrich_session_frame); wall-clock, belongs here not in the parallel suite.tests/perf/test_live_budget.pyβ P3 live budget: 500 symbols within one second (moved fromtests/dsl/test_dsl_detector_series.pyfor the same xdist reason).tests/perf/test_series_eval_budget.pyβ per-symbol whole-frame gate forcore/dsl/series_eval.py(ENRICH_BUDGET_MS); absolute, uncalibrated budget (the Β§6 target from the removed performance plan is not reachable without changing what the function returns).tests/perf/test_calendar_export_budget.pyβ PERF-P2 calendar-export measurements over real cached minute frames; asserts a perf run rewrites or deletes nothing in the cache.
Concurrency guards (tests/infra/):
test_perf_batch_ohlc_singleflight.pyβ concurrent cold OHLC requests for one symbol/timeframe share one upstream fetch (singleflight keyed on the route's cache key).test_perf_batch_cached_stampede.py,test_perf_batch_news_feed.py,test_perf_batch_symbol_search_cache.pyβ batch-cache behavior under repeated cold requests.
3. Removed performance plan
A performance plan (PERF-P1 p95 target, PERF-P2 calendar export, PERF-P3 live budget) was removed on 2026-10-17; see git history. Its targets survive as the committed baselines and serial budget files above, not as a separate document.
4. Local gates only
Performance checks are local, never remote CI. Full gate: make ci (includes
js, lint, test, test-js, smoke-fast); fast iteration loop:
make check-fast then make verify-diff (alias make ci-agent). Serial perf
runs separately with make perf-benchmark / make perf-check.
5. How to verify a change
- Reproduce on a quiet machine, serially (
make perf-benchmark), never underpytest -n auto. - Compare against the committed baseline (
make perf-check). - For
/discover, re-check the DevTools stages above before and after the change. - Confirm no cache file under the cached frame directory is rewritten or
deleted by a perf run (see
test_calendar_export_budget.py).
6. Dates
Dates in this document use YYYY-MM-DD. The performance plan was removed
2026-10-17; the serial budget files were moved into tests/perf/ at the same
time (see git history).