减少日频数据读取临时分配

This commit is contained in:
boris
2026-08-26 04:46:08 +08:00
parent d071a8a190
commit 6604afd24f
5 changed files with 23 additions and 9 deletions
+14
View File
@@ -2456,6 +2456,13 @@ impl DataSet {
.unwrap_or_default()
}
pub fn market_snapshot_rows_on(&self, date: NaiveDate) -> &[DailyMarketSnapshot] {
self.market_by_date
.get(&date)
.map(Vec::as_slice)
.unwrap_or(&[])
}
pub fn candidate_snapshots_on(&self, date: NaiveDate) -> Vec<&CandidateEligibility> {
self.candidate_by_date
.get(&date)
@@ -2463,6 +2470,13 @@ impl DataSet {
.unwrap_or_default()
}
pub fn candidate_snapshot_rows_on(&self, date: NaiveDate) -> &[CandidateEligibility] {
self.candidate_by_date
.get(&date)
.map(Vec::as_slice)
.unwrap_or(&[])
}
pub fn bundle_on(&self, date: NaiveDate) -> Result<DailySnapshotBundle, DataSetError> {
let benchmark = self
.benchmark(date)
+3 -3
View File
@@ -1778,11 +1778,11 @@ where
.filter(|date| self.config.end_date.map(|end| *date <= end).unwrap_or(true))
.collect::<Vec<_>>();
let has_decision_inputs = |date: NaiveDate| {
!self.data.factor_snapshots_on(date).is_empty()
&& !self.data.candidate_snapshots_on(date).is_empty()
!self.data.factor_snapshot_rows_on(date).is_empty()
&& !self.data.candidate_snapshot_rows_on(date).is_empty()
};
let has_execution_market =
|date: NaiveDate| !self.data.market_snapshots_on(date).is_empty();
|date: NaiveDate| !self.data.market_snapshot_rows_on(date).is_empty();
let mut execution_dates = Vec::new();
let mut decision_slots = Vec::new();
for (calendar_idx, execution_date) in calendar_dates.iter().copied().enumerate() {
@@ -3678,8 +3678,8 @@ impl PlatformExprStrategy {
is_month_end,
available_factor_names: if self.stock_extra_factors_required {
ctx.data
.factor_snapshots_on(date)
.into_iter()
.factor_snapshot_rows_on(date)
.iter()
.flat_map(|row| row.extra_factors.keys().map(|key| key.to_string()))
.collect()
} else {
@@ -7797,7 +7797,7 @@ impl PlatformExprStrategy {
return;
};
let mut map = Map::new();
for snapshot in ctx.data.market_snapshots_on(date) {
for snapshot in ctx.data.market_snapshot_rows_on(date) {
if let Some(value) = Self::market_scope_value(snapshot, field) {
map.insert(snapshot.symbol.clone().into(), Dynamic::from(value));
}
+1 -1
View File
@@ -2541,7 +2541,7 @@ impl OmniMicroCapStrategy {
date: NaiveDate,
) -> Vec<FidcRiskDecisionAudit> {
let mut decisions = Vec::new();
for factor in ctx.data.factor_snapshots_on(date) {
for factor in ctx.data.factor_snapshot_rows_on(date) {
if ctx.has_dynamic_universe() && !ctx.dynamic_universe_contains(&factor.symbol) {
continue;
}
+2 -2
View File
@@ -80,7 +80,7 @@ impl SelectionContext<'_> {
}
};
let mut decisions = Vec::new();
for factor in self.data.factor_snapshots_on(self.decision_date) {
for factor in self.data.factor_snapshot_rows_on(self.decision_date) {
if self
.dynamic_universe
.is_some_and(|symbols| !symbols.is_empty() && !symbols.contains(&factor.symbol))
@@ -213,7 +213,7 @@ impl UniverseSelector for DynamicMarketCapBandSelector {
risk_decisions: Vec::new(),
};
diagnostics.factor_total = ctx.data.factor_snapshots_on(ctx.decision_date).len();
diagnostics.factor_total = ctx.data.factor_snapshot_rows_on(ctx.decision_date).len();
diagnostics.risk_decisions = ctx.selection_risk_decisions();
diagnostics.not_eligible_count = diagnostics.risk_decisions.len();
diagnostics.paused_count = diagnostics