From f41e7496adf6ec066b7258c6440dc340bfaac3a3 Mon Sep 17 00:00:00 2001 From: Eunchurn Park Date: Fri, 26 Dec 2025 13:38:00 +0900 Subject: [PATCH] perf(parser): only show progress bar for chapters >= 50KB - Fix progress check logic: use lastProgress/10 != progress/10 to catch any 10% boundary crossing instead of requiring exact 10% match - Only show progress bar for chapters >= 50KB where rendering overhead is worth the visual feedback --- lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp index 0b1bb8db..d2f1c3e6 100644 --- a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp +++ b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp @@ -11,6 +11,9 @@ const char* HEADER_TAGS[] = {"h1", "h2", "h3", "h4", "h5", "h6"}; constexpr int NUM_HEADER_TAGS = sizeof(HEADER_TAGS) / sizeof(HEADER_TAGS[0]); +// Minimum file size (in bytes) to show progress bar - smaller chapters don't benefit from it +constexpr size_t MIN_SIZE_FOR_PROGRESS = 50 * 1024; // 50KB + const char* BLOCK_TAGS[] = {"p", "li", "div", "br", "blockquote"}; constexpr int NUM_BLOCK_TAGS = sizeof(BLOCK_TAGS) / sizeof(BLOCK_TAGS[0]); @@ -255,10 +258,11 @@ bool ChapterHtmlSlimParser::parseAndBuildPages() { } // Update progress (call every 10% change to avoid too frequent updates) + // Only show progress for larger chapters where rendering overhead is worth it bytesRead += len; - if (progressFn && totalSize > 0) { + if (progressFn && totalSize >= MIN_SIZE_FOR_PROGRESS) { const int progress = static_cast((bytesRead * 100) / totalSize); - if (progress != lastProgress && progress % 10 == 0) { + if (lastProgress / 10 != progress / 10) { lastProgress = progress; progressFn(progress); }