Skip to content

perf: lazily materialize signal inputs#14

Open
Votienduong2208 wants to merge 1 commit into
Dragoon4002:mainfrom
Votienduong2208:perf/lazy-signal-inputs
Open

perf: lazily materialize signal inputs#14
Votienduong2208 wants to merge 1 commit into
Dragoon4002:mainfrom
Votienduong2208:perf/lazy-signal-inputs

Conversation

@Votienduong2208

Copy link
Copy Markdown

Summary

  • Lazily materialize price_history and candle dictionaries inside compute_strategy_signal
  • Avoids converting the candle cache for price-only strategies like momentum, macd_signal, z_score, etc.
  • Avoids converting price_history for pure OHLC strategies when they do not need it
  • Preserves existing dispatcher outputs; this is an allocation/CPU optimization only

Closes #2

Why it is faster

Before this change, every signal tick eagerly did both:

  1. list(price_history)
  2. List[Candle] -> List[dict]

That happened even when the selected strategy only needed one of those inputs. With a candle cache present, common price-only strategies paid the full OHLC conversion cost every tick and then discarded it.

This PR wraps those conversions in small lazy helpers so each strategy path only pays for the input it actually uses.

Validation

Ad-hoc verification script (temporary C:\Users\Admin\AppData\Local\Temp\hermes-verify-artic-signals-lazy.py, cleaned up after run):

PASS output-equivalence strategies=8 candles=3000 prices=3000
BENCH momentum price-only with candle cache present: old=4.301242s new=0.111722s speedup=38.50x loops=5000
BENCH macd price-only with candle cache present: old=2.093392s new=1.336851s speedup=1.57x loops=1000
BENCH supertrend OHLC-only with long price history: old=2.292524s new=2.312867s speedup=0.99x loops=1000
BENCH adx_filter OHLC-only with long price history: old=3.520307s new=3.382011s speedup=1.04x loops=1000

Additional checks:

python -m py_compile app/strategies/signals.py
 git diff --check

Both passed.

Notes

This targets a distinct dispatcher-level allocation bottleneck from the other issue #2 submissions. It improves the common engine path where self._candle_cache is populated but the active strategy is price-history based.

If selected for payout: USDC on Base address can be provided privately after acceptance.

@vercel

vercel Bot commented Jun 29, 2026

Copy link
Copy Markdown

@Votienduong2208 is attempting to deploy a commit to the dragoon4002's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Votienduong2208

Copy link
Copy Markdown
Author

Contributor-side status check: this PR is mergeable. The visible failing Vercel status points to the repo-owner/team GitHub authorization URL, which appears to be the same repository-level Vercel authorization gate seen on the other bounty PRs rather than a code-specific failure. Local validation passed: python -m py_compile app/strategies/signals.py and git diff --check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improvements Bounty: Performance Enhancer

1 participant