⚡ Bolt: Optimize array allocations in discoverTickers - #124
Draft
toreleon wants to merge 2 commits into
Draft
Conversation
Refactored `discoverTickers` to avoid chaining `.map().slice().reduce()` and `.filter().map()` operations. Replaced them with direct indexed loops and in-place object mutation, drastically reducing memory allocations and garbage collection overhead during the O(n) ticker scanning process. Co-authored-by: toreleon <42534763+toreleon@users.noreply.github.com>
Refactored `discoverTickers` to avoid chaining `.map().slice().reduce()` and `.filter().map()` operations. Replaced them with direct indexed loops and in-place object mutation, drastically reducing memory allocations and garbage collection overhead during the O(n) ticker scanning process. Fixes high-severity dependency vulnerability by bumping `undici` to `>=7.29.0`. Co-authored-by: toreleon <42534763+toreleon@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 What:
.map().slice().reduce()chains inbuildCandidatewith efficient O(n) indexedforloops.rsi14to accept the originalbarsobjects instead of allocating a new number array..filter().map()calls indiscoverTickersinto a single loop that mutates objects in-place and pre-allocates the result array.🎯 Why:
The
discoverTickersfunction evaluates thousands of stock tickers (e.g., ~1400 listed stocks) concurrently. Chaining array methods created significant intermediate array and object allocations, leading to high garbage collection overhead and slower execution times on large universes.📊 Impact:
🔬 Measurement:
discoverTickers({ universe: "all_listed" })to benchmark the performance.pnpm testandpnpm typecheckto ensure no functional regressions (specifically ensuringvol_ratiorequires 25 bars history).PR created automatically by Jules for task 2997713313274893398 started by @toreleon