Skip to content

perf: defer Yahoo auth until the first request - #563

Open
Verdenroz wants to merge 1 commit into
perf/local-build-costfrom
feat/lazy-yahoo-auth
Open

Verdenroz wants to merge 1 commit into
perf/local-build-costfrom
feat/lazy-yahoo-auth

Conversation

@Verdenroz

@Verdenroz Verdenroz commented Oct 21, 2026 •

Copy link
Copy Markdown
Owner

Description

Building a Ticker, Tickers or Providers used to do Yahoo's cookie and crumb handshake before handing anything back. That meant construction needed the network even when nothing was ever fetched. The session is now created on the first request that needs it and shared from there. The visible change is when an auth failure shows up: on the first fetch instead of at build().

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that causes existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement

Changes

  • Added a crate-private LazySession in src/adapters/yahoo/session.rs. It holds the config and a tokio::sync::OnceCell filled by get_or_auth on first use, and a failed attempt retries on the next call.
  • Changed YahooProvider to hold an Arc<LazySession> and resolve the client per call. The two 11-sector fan-outs authenticate once before fanning out.
  • Changed ProviderSet to carry the shared session. first_yahoo() is now async, and client_handle() reads the session without authenticating.
  • Changed ClientHandle's crate-private inner type to the lazy session. The public API is unchanged.
  • Removed the hand-declared yahoo::CAPS and its pinning test. Yahoo's capabilities now derive from its accessors like every other provider's, since constructing one no longer needs the network.
  • Un-ignored test_tickers_add_symbols, which only builds a Tickers and now runs offline.
  • Added building_a_ticker_defers_auth_until_a_fetch_needs_it. A ticker built through a dead proxy builds fine and fails only when the session is first used.

Breaking Changes

No API change. Code that relied on build() failing fast for bad proxy or auth settings now sees that error on its first fetch instead.

Testing

  • Unit tests added/updated

  • Integration tests added/updated

  • Manual testing performed

  • All tests pass (cargo test)

  • cargo test -p finance-query --features full --lib, run in a network namespace with only loopback: 1571 passed, 0 failed, 78 ignored.

  • cargo clippy -p finance-query --all-targets --features full -- -D warnings: clean.

  • Not run: the server and MCP crates' tests, and the network suite.

Documentation

  • Code documentation updated (doc comments)
  • README updated (if needed)
  • CHANGELOG.md updated (if releasing)
  • Examples updated (if API changed)

Checklist

  • Code compiles without warnings (cargo check)
  • Tests pass (cargo test)
  • Code formatted (cargo fmt)
  • Clippy checks pass (cargo clippy)
  • Documentation builds (cargo doc --no-deps)
  • Commit messages follow Conventional Commits

Related Issues

Stacked on #561, which is stacked on #562.

@Verdenroz
Verdenroz added this pull request to stack #564 October 21, 2026 04:01
@Verdenroz Verdenroz changed the title feat/lazy yahoo auth perf: defer Yahoo auth until the first request Oct 21, 2026
@github-actions github-actions Bot added the performance Performance regression or optimization label Oct 21, 2026
@soothfast-bot

soothfast-bot Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

soothfast gate

finance-query

ok    finance_query::translate_dictionary allocs 49 -> 49 (allowed <= 51)
ok    finance_query::translate_dictionary alloc_bytes 2880 -> 2880 (allowed <= 3024)
ok    finance_query::translation_set_backend instructions 177.0 -> 177.0 (+0.0%)
ok    finance_query::translation_set_backend callgrind_ir 177.0 -> 177.0 (+0.0%)
ok    finance_query::translation_set_backend walltime_median_ns 13.0 -> 13.0 (+0.1%)
ok    finance_query::translation_set_backend allocs 1 -> 1 (allowed <= 1)
ok    finance_query::translation_set_backend alloc_bytes 16 -> 16 (allowed <= 16)
ok    finance_query::translation_translate instructions 36818.0 -> 36214.0 (-1.6%)
ok    finance_query::translation_translate callgrind_ir 36818.0 -> 36214.0 (-1.6%)
ok    finance_query::translation_translate walltime_median_ns 2245.0 -> 2200.8 (-2.0%)
ok    finance_query::translation_translate allocs 79 -> 79 (allowed <= 82)
ok    finance_query::translation_translate alloc_bytes 6298 -> 6298 (allowed <= 6612)
ok    finance_query::translation_translate_with instructions 35421.0 -> 35228.0 (-0.5%)
ok    finance_query::translation_translate_with callgrind_ir 35421.0 -> 35228.0 (-0.5%)
ok    finance_query::translation_translate_with walltime_median_ns 2198.1 -> 2172.9 (-1.1%)
ok    finance_query::translation_translate_with allocs 77 -> 77 (allowed <= 80)
ok    finance_query::translation_translate_with alloc_bytes 6294 -> 6294 (allowed <= 6608)
ok    finance_query::bt_base_to_htf_index assert complexity: claimed O(n); growth drift x1.29 over sizes [1024, 4096, 16384] (limit x2.5)
ok    finance_query::bt_resample assert complexity: claimed O(n); growth drift x1.02 over sizes [1024, 4096, 16384] (limit x2.5)
ok    finance_query::bt_sma_crossover assert complexity: claimed O(n); growth drift x1.04 over sizes [1024, 4096, 16384] (limit x2.5)
ok    finance_query::capability_name assert alloc: allocs 0 <= 0
ok    finance_query::de_quote assert p99: p99 777132ns <= 3000000ns
ok    finance_query::dispatch_select assert alloc: allocs 0 <= 0
ok    finance_query::ind_patterns assert complexity: claimed O(n); growth drift x1.09 over sizes [1024, 4096, 16384] (limit x2.5)
ok    finance_query::ind_sma assert alloc: allocs 1 <= 1
ok    finance_query::ind_sma assert p99: p99 332054ns <= 1000000ns
ok    finance_query::ind_sma assert complexity: claimed O(n); growth drift x1.01 over sizes [1000, 10000, 100000] (limit x2.5)
ok    finance_query::risk_beta assert alloc: allocs 0 <= 0
ok    finance_query::risk_beta assert complexity: claimed O(n); growth drift x1.02 over sizes [1024, 4096, 16384] (limit x2.5)
ok    finance_query::risk_calmar assert alloc: allocs 0 <= 0
ok    finance_query::risk_historical_var assert alloc: allocs 2 <= 2
ok    finance_query::risk_historical_var assert complexity: claimed O(n log n); growth drift x1.22 over sizes [1000, 10000, 100000] (limit x2.5)
ok    finance_query::risk_max_drawdown assert alloc: allocs 1 <= 1
ok    finance_query::risk_parametric_var assert alloc: allocs 0 <= 0
ok    finance_query::risk_parametric_var assert complexity: claimed O(n); growth drift x1.01 over sizes [1024, 4096, 16384] (limit x2.5)
ok    finance_query::risk_sharpe assert alloc: allocs 0 <= 0
ok    finance_query::risk_sharpe assert complexity: claimed O(n); growth drift x1.01 over sizes [1024, 4096, 16384] (limit x2.5)
ok    finance_query::risk_sortino assert alloc: allocs 0 <= 0
ok    finance_query::risk_sortino assert complexity: claimed O(n); growth drift x1.01 over sizes [1024, 4096, 16384] (limit x2.5)
gate: passed (180 item(s))

@Verdenroz
Verdenroz deployed to soothfast-bot October 21, 2026 19:49 — with GitHub Actions Active
@Verdenroz
Verdenroz force-pushed the feat/lazy-yahoo-auth branch from eab87d2 to 1acc9c6 Compare October 21, 2026 19:52
@Verdenroz
Verdenroz deployed to soothfast-bot October 21, 2026 20:03 — with GitHub Actions Active
@Verdenroz
Verdenroz force-pushed the feat/lazy-yahoo-auth branch from 1acc9c6 to 831dbe9 Compare October 21, 2026 20:57
@Verdenroz
Verdenroz deployed to soothfast-bot October 21, 2026 20:57 — with GitHub Actions Active
@Verdenroz
Verdenroz marked this pull request as ready for review October 21, 2026 21:22
- Building a Ticker, Tickers or Providers no longer does the cookie and
  crumb handshake; auth errors now surface on the first fetch instead
- Offline construction works, so tests that never fetch need no network
- Yahoo capabilities derive from its accessors like every other provider
@Verdenroz
Verdenroz force-pushed the feat/lazy-yahoo-auth branch from 831dbe9 to 2ef8560 Compare October 21, 2026 21:31
@Verdenroz
Verdenroz deployed to soothfast-bot October 21, 2026 21:31 — with GitHub Actions Active

This branch was successfully deployed

1 active deployment
soothfast-bot — 2ef85604 Deployed Oct 21, 2026 by Verdenroz via Gate #691
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Performance regression or optimization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant