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:
co-authored by
Erica Jensen
Uri Tauber
parent
a43061305a
commit
4fb843ef92
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user