Commit ae1f4673 ae1f4673085c3484c8506d53e630270994f5c607 by cnb.bofCdSsphPA

Reduce chromaprint peak-scan cost without changing fingerprint output

Constraint: the live FMA smoke is still running, so the optimization had to preserve existing hash semantics rather than adopt the faster non-equivalent peak picker
Rejected: maximum_filter-based peak picking | changed peak/hash outputs despite much larger speedup
Confidence: high
Scope-risk: narrow
Directive: Keep future chromaprint optimizations hash-equivalent unless evaluation baselines are intentionally regenerated
Tested: compared old vs new peaks and hashes on fma_00000.mp3, measured 2.02x speedup, py_compile passed, rechecked live FMA smoke still in build-index
Not-tested: full build-index completion on the live 8000-reference FMA run has not finished yet
1 parent 8328bc79
......@@ -9,6 +9,7 @@ Implements landmark-based audio fingerprinting:
import numpy as np
import librosa
from numpy.lib.stride_tricks import sliding_window_view
from collections import defaultdict
from typing import Dict, List, Tuple, Optional
import pickle
......@@ -53,13 +54,18 @@ class ChromaprintMatcher:
return S
def _find_peaks(self, S: np.ndarray) -> List[Tuple[int, int, float]]:
peaks = []
for t in range(0, S.shape[1] - self.peak_neighborhood):
for f in range(0, S.shape[0] - self.peak_neighborhood):
region = S[f:f + self.peak_neighborhood, t:t + self.peak_neighborhood]
center = S[f, t]
if center == np.max(region) and center > self.min_peak_energy:
peaks.append((t, f, center))
if S.shape[0] <= self.peak_neighborhood or S.shape[1] <= self.peak_neighborhood:
return []
windows = sliding_window_view(S, (self.peak_neighborhood, self.peak_neighborhood))[:-1, :-1]
region_max = windows.max(axis=(-1, -2))
centers = S[: S.shape[0] - self.peak_neighborhood, : S.shape[1] - self.peak_neighborhood]
mask = (centers == region_max) & (centers > self.min_peak_energy)
peaks = [
(int(t), int(f), float(centers[f, t]))
for f, t in np.argwhere(mask)
]
peaks.sort(key=lambda x: x[2], reverse=True)
return peaks[:200]
......
## 2026-06-02 chromaprint peak scan exact-safe optimization checkpoint
完成项:
-`acr-engine/src/engines/chromaprint_matcher.py``_find_peaks()` 从 Python 双层循环改为 `sliding_window_view` 向量化窗口最大值实现。
- 放弃了更激进但会改变 hash 结果的 `maximum_filter` 方案,改用严格保持旧语义的等价版本。
验证结果:
- 单曲样本 `/tmp/fma_real_smoke_stopcheck/fma/audio/fma_00000.mp3`
- `old_sec=1.3305`
- `new_sec=0.6579`
- `speedup_x=2.02`
- 等价性验证:
- `same_all200=true`
- `same_hashes=true`
- `old_hashes=609`
- `new_hashes=609`
- `python -m py_compile src/engines/chromaprint_matcher.py` 通过
- 长跑中的真实 FMA smoke 在 `2026-06-02 13:49:25 UTC` 仍处于 `build-index`,尚未产出 `chromaprint.pkl` / `reference_progress.json`
结论:
- 这次提交安全降低了 chromaprint 峰值扫描热点成本,且不改变当前 fingerprint/hash 行为。
- 后续可继续观察真实 FMA 全量 smoke 是否更快进入 `chromaprint.pkl` 或 embedding checkpoint。
## 2026-06-02 真实 FMA smoke build-index 13:36 UTC delivery checkpoint
完成项:
......