feat(images): add reference resolution cache to avoid expensive parsing#295
feat(images): add reference resolution cache to avoid expensive parsing#295uran0sH wants to merge 1 commit intoboxlite-ai:mainfrom
Conversation
Add fast-path cache for image references to avoid costly `ReferenceIter::new()` parsing (364ms cold start). **Changes:** - New `reference_resolution` table mapping short refs (e.g., "alpine:latest") to resolved full refs - Fast-path lookup before parsing: check cache first, only parse on miss - Store resolution mapping after successful pull for future reuse **Performance:** - Cache hit: ~µs (DB lookup) vs 364ms (parsing) - Cache miss: No regression (same as before) Signed-off-by: Wenyu Huang <huangwenyuu@outlook.com>
|
Hi @uran0sH, Thanks for the effort here! I dug into the root cause and want to share some findings. The 364ms figure comes from oci_spec::distribution::Reference::parse() triggering a cold regex compilation via OnceLock. I benchmarked this on Apple Silicon (release mode): Cold parse (regex compile + match): 40.8ms The key thing is — OnceLock means this cost is paid once per process lifetime, not per call. After the first ImageStore::pull(), every subsequent parse in the same BoxliteRuntime process reuses the So adding a DB cache + new table to avoid a one-time 40ms cost feels like over-engineering — it introduces ongoing schema/migration complexity for a problem that only exists on the very first image Before we merge this, a few questions:
|
Perhaps this PR doesn't need to be merged; we just need to know that there is a relatively large overhead during the cold start. |
Add fast-path cache for image references to avoid costly
ReferenceIter::new()parsing (364ms cold start).Changes:
reference_resolutiontable mapping short refs (e.g., "alpine:latest") to resolved full refsPerformance: