From 5a6c361c11ba0e525428e5060975a79bf0870b8f Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Wed, 9 Sep 2026 09:04:10 -0400 Subject: [PATCH] perf(sync): share the bounded converter cache for section percentages Per-annotation percentage derivation (deriveAnnotationPercentage) built a fresh CFIConverter for every highlight/note/bookmark, re-reading and re-parsing the whole EPUB each time. Export SectionPercentageCached so handlers reach the same bounded cache ConvertToCanonical already uses (8 books, insertion-order eviction): one parse per book per push instead of one per annotation. --- internal/sync/locators.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/sync/locators.go b/internal/sync/locators.go index 28acdda..c371226 100644 --- a/internal/sync/locators.go +++ b/internal/sync/locators.go @@ -58,6 +58,13 @@ func cachedConverter(epubPath string) *CFIConverter { return c } +// SectionPercentageCached resolves the spine-section percentage of a CRE +// xpointer through the shared bounded converter cache, so per-annotation +// lookups parse the EPUB once per book instead of once per annotation. +func SectionPercentageCached(epubPath, xpointer string) float64 { + return cachedConverter(epubPath).SectionPercentage(xpointer) +} + func ConvertToCanonical( source LocatorSource, devicePos string,