perf(factor): universe parquet缓存——外部~20min杀手 regime下每条命15min冷加载翻转为秒级复载,20min寿命=纯计算15-20因子;key含窗口/symbols/limit防串池,写失败静默 [vps]
This commit is contained in:
@@ -35,6 +35,16 @@ def load_universe_bars(
|
||||
datetime.strptime(end, "%Y-%m-%d") + timedelta(days=_FORWARD_DAYS)
|
||||
).strftime("%Y-%m-%d")
|
||||
|
||||
# 缓存短路:含窗口/symbols/limit防串池
|
||||
import os as _os
|
||||
cache_path = _os.path.join(
|
||||
_os.path.dirname(_os.path.abspath(vnpy_db)),
|
||||
f"universe_cache_{start}_{end}_{len(symbols) if symbols else 'all'}"
|
||||
f"{'_'+str(limit) if limit else ''}.parquet"
|
||||
)
|
||||
if _os.path.exists(cache_path):
|
||||
return pl.read_parquet(cache_path)
|
||||
|
||||
if symbols is None:
|
||||
conn = sqlite3.connect(vnpy_db, timeout=60)
|
||||
try:
|
||||
@@ -100,6 +110,13 @@ def load_universe_bars(
|
||||
.with_columns(pl.int_range(pl.len()).over("vt_symbol").alias("bar_idx"))
|
||||
.collect()
|
||||
)
|
||||
|
||||
# 写缓存(失败静默,不影响主流程)
|
||||
try:
|
||||
df.write_parquet(cache_path)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return df
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user