Repository navigation
perf(reader): read books as lines, no join and re-split on open - #5876
KleiKodesh wants to merge 2 commits into
Conversation
A seforim.db book was read as rows, joined with newlines into one string and split again on newlines for the viewer. Each source now hands over a list of lines: database rows directly (BookTextReader.lines, worker method bookLines, getBookLinesFromDb; official, user-books and attached databases), a text file split once (BookLinesProvider, LibraryProviderManager.getBookLines, TextBookRepository.getBookLines). getBookText / getBookContent are joins of the lines, built on demand for consumers that need one string. Lines equal the old text split on newlines in every path (BOM per row, rows holding a newline, UTF-16, empty books).
The text book bloc (initial load, background full load) and the screen (in-book search loader, context-menu line lookup) take TextBookRepository.getBookLines instead of splitting getBookContent. splitContentLines is gone (splitBookText replaces it). Test repositories that override getBookContent also serve getBookLines from it.
|
סוגר את ה־PR לאחר סקירת שרשרת הקריאה. במסלול הרגיל לפתיחת ספר רשמי הקורא מתחיל בטווח שורות, והמדידה כאן משווה טעינה מלאה. בטעינה המלאה עצמה המדידות בתיאור אינן מראות שיפור עקבי, ושיא הזיכרון טרם נמדד. ה־API שמחזיר מחרוזת מעביר כעת רשימה של ספר שלם מה־worker ומחבר אותה ב־UI isolate. למשל, צורת הדף עושה זאת בטעינה מלאה של מפרש ממסד מצורף, ואז מפצלת את התוצאה שוב. גם ייצוא, הדפסה ותוספים עוברים בנתיב המחרוזת שהשתנה. התקבל כאן מעבר עבודה ל־UI במסלולים שמשתמשים בהם בפועל, בלי שיפור מדוד שמצדיק את היקף השינוי. תיקון המשך מתאים יכול לשמר את נתיב המחרוזת הישיר, להוסיף קריאת שורות רק לצרכנים שצריכים אותה, ולמדוד זמן ושיא זיכרון בפתיחת ספר ובטעינת מפרש ממסד מצורף. |
|
@KleiKodesh |
|
נאום קודקס: |
|
לא - הכל בנוי על מידע שגוי שניתן לי ל ידי קלוד.
אל תקבל את זה בשו נים ואפן
…On Mon, Nov 23, 2026 at 4:58 PM Y-Ploni ***@***.***> wrote:
*Y-PLONI* left a comment (Otzaria/otzaria#5876)
<#5876 (comment)>
נאום קודקס:
יש חלק שעשוי להיות שווה להציל: להחזיר שורות ישירות לקורא כשהוא ממילא צריך
אותן, ולשמר את מסלול המחרוזת הקיים לייצוא, להדפסה ולתוספים. לא בניתי ומדדתי
את הגרסה הממוקדת הזאת לפני הסגירה. לכן יש בסיס לסגור את הריפקטור כפי שהוגש,
והשאלה אם כדאי לתקן אותו בגרסה מצומצמת עדיין פתוחה.
—
Reply to this email directly, view it on GitHub
<#5876?email_source=notifications&email_token=BSQRU6LTCH57WTPAD6S6AFL52RGCRA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTOMJQGQ4DENRTGU2KM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#issuecomment-7104826354>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BSQRU6OKEHZTFVLENBJYPUT52RGCRAVCNFSNUABGKJSXA33TNF2G64TZHMYTAMBQGUZDOOJZGY5US43TOVSTWNRVGU3TSMRRGU3DFILWAI>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/BSQRU6P3BQLZ3CYIPWDJSW352RGCRA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTOMJQGQ4DENRTGU2KM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJKTGN5XXIZLSL5UW64Y>
and Android
<https://github.com/notifications/mobile/android/BSQRU6O54H6OOWEX3V4TSU352RGCRA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTOMJQGQ4DENRTGU2KM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLTGN5XXIZLSL5QW4ZDSN5UWI>.
Download it today!
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Problem
Opening a book from seforim.db read its rows, joined them with
\ninto one string (BookTextReader/getBookTextFromDb/DatabaseLibraryProvider.getBookText), and the viewer then split that string on\nagain (splitContentLines, called fromTextBookBlocinitial load, background full load, and fromTextBookScreen). The join and the re-split are wasted work on every book open.Design
One format for every book source: a list of lines.
readBookContentLines/BookTextReader.lines(worker methodbookLines, same book slot asbookText),SqliteDataProvider.getBookLinesFromDb. This covers the official DB, the user-books DB and attached libraries (DatabaseLibraryProvider.getBookLines).FileSystemLibraryProvider.getBookLines,splitBookText).BookLinesProvider(same pattern asLinkLinesProvider).LibraryProviderManager.getBookLinesuses it, or splits a provider's text once.TextBookRepository.getBookLinesmirrorsgetBookContent, including the version overlay and the DB fallback.getBookLines.getBookText/getBookContentare now joins of the lines, built on demand. They are kept only for consumers that genuinely need one string: export, print, the plugin APIlibrary.getBookContent, tikkun korim. Indexing and personal notes keepgetBookTextFromDb/getBookTextBytesFromDbunchanged.Behaviour unchanged
Lines equal the old text split on
\non every path:\nbecomes several lines, as the split made it[]TextBookRepositorybook_text_reader_testnow checks that the lines equal the legacy joined text split on\nin every existing case: the official worker, the untrusted isolate, the main connection, andgetBookLinesFromDb. Newbook_lines_testcovers a text-file book (lines == its text split), the manager with a text-only provider and with a lines provider, and the helpers. On the real seforim.db, every measured book's lines equal its row count and the old split output.Measurements
Real
seforim.dbon the official worker path. Old =BookTextReader.text+ split in an isolate, as the viewer did. New =BookTextReader.lines. Median of 7 runs, on a desktop that was also running other load:A second run gave 4144 vs 4104 ms for the largest book. Read directly on one connection (no isolates), the largest book takes 2500 ms for the joined read, 336 ms for the split, and 2734 ms for the lines read. So the join + split was about 10 % of the open. Decoding each row separately costs about the same as that split, and reading the rows (decompression and SQL) dominates. The timing difference is within noise. The win is structural: one format, no re-split, and no full-book string held next to its lines on the viewer path. Peak memory was not measured.
Tests
flutter analyze: clean for this change.test/data_providers,test/data,test/text_book/bloc,test/text_book/utils/link_processing_test.dart,test/text_book/view/combined_view,simple_text_viewer_test, and every test file touched here.devwithout this change (Windows paths and file locks):custom_folder_add_worker_testsqlite_schema_gate_index_testlinks_load_coalescing_testtext_book_screen_actions_testOverlapping open PRs
Checked with
git merge-tree.devitself. כותרות ספרים: שם שמור בלי גרשיים ממשיך לפתוח את הספר המתוקן (#2766) #5634 toucheslibrary_provider_manager.dartand מפרשים: זיהוי אותו מפרש בין ספרים לפי שם האוסף, בלי התאמת קידומת (#2704) #3442 touchestext_book_repository.dart, which this PR also changes.