Skip to content

perf: cache parsed instrument dates - #244

Open
raus7n wants to merge 1 commit into
zerodha:masterfrom
raus7n:perf/cache-instrument-dates
Open

raus7n wants to merge 1 commit into
zerodha:masterfrom
raus7n:perf/cache-instrument-dates

Conversation

@raus7n

@raus7n raus7n commented Sep 13, 2026

Copy link
Copy Markdown

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.

Signed-off-by: Raushan Kumar <raus7n@gmail.com>
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.

1 participant