Repository navigation
Conversation
Signed-off-by: Raushan Kumar <raus7n@gmail.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.
Summary
Cache parsed instrument dates locally while processing instrument CSV responses.
Both _parse_instruments and _parse_mf_instruments can encounter multiple rows with identical date values. Previously, each row independently called dateutil.parser.parse, resulting in repeated parsing of the same date strings.
This change introduces per-parse-operation caches for:
expiry in _parse_instruments
last_price_date in _parse_mf_instruments
Motivation
Instrument dumps can contain thousands of rows, while many instruments may share the same expiry or valuation date.
For N rows containing U unique date strings, this reduces date parsing from approximately N parser calls to U parser calls, while preserving the existing parsing behavior and output.
Implementation
The caches are local to each parsing operation and are discarded after the method returns.
The existing dateutil.parser.parse(...).date() logic is preserved, so accepted date formats and parsing semantics remain unchanged.
Impact
This avoids redundant parsing work and reduces unnecessary CPU usage when instrument CSV data contains repeated dates.
Scope
This PR only caches repeated date parsing within instrument CSV processing. It does not change the parser implementation or historical-data timestamp parsing.