perf: skip redundant progress writes when position is unchanged (#2436)

Co-authored-by: Erica Jensen <erica@mailershaven.com>
Co-authored-by: Uri Tauber <uritaube@gmail.com>
This commit is contained in:
hooligan333
2026-07-10 10:37:43 +03:00
committed by GitHub
co-authored by Erica Jensen Uri Tauber
parent a43061305a
commit 4fb843ef92
2 changed files with 17 additions and 1 deletions
+11 -1
View File
@@ -1207,7 +1207,17 @@ void EpubReaderActivity::render(RenderLock&& lock) {
renderContents(std::move(p), orientedMarginTop, orientedMarginRight, orientedMarginBottom, orientedMarginLeft);
LOG_DBG("ERS", "Rendered page in %dms", millis() - start);
}
saveProgress(currentSpineIndex, section->currentPage, section->estimatedTotalPages());
// Only persist when the position actually changed. render() also runs on menu,
// bookmark and screenshot re-renders, and writeAtomic is several FAT ops for 6 bytes.
// Every real page turn changes currentPage, so progress durability is unaffected.
if (currentSpineIndex != lastSavedSpineIndex || section->currentPage != lastSavedPage ||
section->pageCount != lastSavedPageCount) {
if (saveProgress(currentSpineIndex, section->currentPage, section->estimatedTotalPages())) {
lastSavedSpineIndex = currentSpineIndex;
lastSavedPage = section->currentPage;
lastSavedPageCount = section->estimatedTotalPages();
}
}
showPendingSyncSaveError();
@@ -63,6 +63,12 @@ class EpubReaderActivity final : public Activity {
SavedPosition savedPositions[MAX_FOOTNOTE_DEPTH] = {};
int footnoteDepth = 0;
// Last position persisted by render()'s saveProgress, used to skip redundant
// writeAtomic calls on no-op re-renders (menu/bookmark/screenshot).
int lastSavedSpineIndex = -1;
int lastSavedPage = -1;
int lastSavedPageCount = -1;
void renderContents(std::unique_ptr<Page> page, int orientedMarginTop, int orientedMarginRight,
int orientedMarginBottom, int orientedMarginLeft);
void renderStatusBar() const;