Repository navigation
perf: cut the live typeset round trip from 7.4 s to 2.1 s on 100 pages - #41
Merged
Merged
Conversation
Every edit typesets the whole document in tok-cli and ships the layout to the renderer. Since 0.36 that round trip is ~55% slower than 0.35.2: - typeset-document --with-preflight built the output with json!(), which first copies every page and glyph into a serde_json::Value and widens each f32 to f64. Serialize the structs directly instead. - Write compact JSON; the pretty-printed layout was ~1.5 MB per page. - Skip GlyphBox.color_index when it is 0 (the UI does not read it). - Pass the layout to the renderer as the raw JSON string. Parsing it in the main process and cloning the object tree over IPC cost about as much as typesetting. Measured on windows-latest (live round trip, median of 7): 40 pages 2.8 s -> 0.75 s, 100 pages 7.4 s -> 2.1 s, output 201 MB -> 64 MB. Preflight now adds ~35 ms on 100 pages, so it still runs on every edit.
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
הבעיה
ב-#37 עלה שכל התוכנה ב-0.36.1 איטית יותר. אחרי כל עריכה (100–150ms) האפליקציה מעמדת מחדש את כל המסמך ב-
tok-cliושולחת את התוצאה לחלון. מדדתי שהסבב הזה איטי ב-55%–60% מ-0.35.2.מה מדדתי
הרצתי ב-
windows-latestאת אותו מסלול שהאפליקציה מריצה:documentStateToDocumentRoot, כתיבת קובץ,tok-cli typeset-documentעם אותם דגלים, פענוח, העברה בין התהליכים (structured clone), ואזlayoutToPageDescriptors. כל גרסה רצה עם הקוד שלה. התוצאה היא ה-median של 7 הרצות על מסמך עברי מנוקד עם עיצוב בחלק מהפסקאות.הגורמים והתיקונים
--with-preflight(חדש ב-0.36) בנה את הפלט עםjson!(). זה מעתיק כל עמוד וכל גליף ל-serde_json::Value, וממיר כלf32ל-f64(מספרים ארוכים יותר בפלט). כאן זה מסודר ישירות מהמבנים. אחרי התיקון ה-preflight מוסיף בערך 35ms ב-100 עמודים, ולכן הוא ממשיך לרוץ בכל עריכה כמו קודם.GlyphBox.color_indexלא נכתב כשהוא 0. הממשק לא קורא את השדה, ו-#[serde(default)]כבר מחזיר 0 בקריאה.tok:typeset-documentמחזירlayoutJson, והפענוח קורה ב-readTypesetResponseשב-typesetBridge.ts. הפונקציה מקבלת גם את הצורה הישנה (pages/preflight).בדיקות
על הענף הזה עברו
cargo fmt --check,cargo clippy --workspace --all-targets -D warnings,cargo test --workspace,npm run buildו-npm test(273 עברו, 0 נכשלו).מה לא נבדק
layoutToPageDescriptorsלא נכלל בה.