Skip display lists for unchanged pages and profile the build

Patch previews now pass onlyPages into render_json before display-list
construction, so unchanged pages skip both glyph-list building and SVG
serialization. Late arXiv edits drop to p50 187 ms / p95 232 ms; article-basic
stays at 37.5 ms.

The gated profiler now reports build_done/layout_done. Release numbers show the
real bottleneck is build_document (~196 ms), while page layout is ~2 ms;
optimizing the page breaker will not reach <100 ms. Record that finding in the
roadmap. Test count stays 1073.
This commit is contained in:
gloamxun committed 2026-10-27 21:41:56 +08:00
1 parent d124c646a1
commit da30705cd0
2 files changed
+21 -8

No files matched your search

+9 -6
View File
@@ -60,19 +60,22 @@ execution is not a goal.
- `changedPages` already identifies the pages that need repainting.
- Incremental bottlenecks:
- release-mode measurements: article-basic warm buffer edit **37.5 ms**
(one page), arXiv late edit **p50 199 ms / p95 222 ms** (one to two of
(one page), arXiv late edit **p50 187 ms / p95 232 ms** (one to two of
three pages changed), arXiv early/heading edit about **480 ms**; a
one-page simple document meets the <100 ms target, the 3-page arXiv
template and the 10-page target do not;
- patch responses are now serialised only for changed pages; the arXiv late
edit still carried one page at 175 KB, and a heading edit carried two at
315 KB of a 396 KB full response; cache hits return ~170 bytes and 10–40 ms;
- patch responses are serialised only for changed pages, and display lists
are skipped for unchanged pages; the arXiv late edit still carried one page
at 175 KB, and a heading edit carried two at 315 KB of a 396 KB full
response; cache hits return ~170 bytes and 10–40 ms;
- the `scripts/bench-preview.py` harness reproduces these numbers: initial
full, then repeated small buffer edits with HTTP/server latency, bytes and
changedPages;
- there is no WebSocket/SSE stream yet, only request/response patches;
- layout is still full-document after parsing the whole buffer; parsing and
geometry are only ~10 ms of the release pipeline, so layout is the target.
- release profiling shows the real bottleneck is **build_document**, not page
layout: for the arXiv late edit geometry ≈5 ms, paragraphs ≈6 ms,
build_document ≈196 ms, layout ≈2 ms. The next optimization must reuse or
cache paragraph units/math layout, not the page breaker.
- Developer profiling: `TEXRRA_PROFILE=1` prints geometry/paragraph/before-render
timings from the project preview path. Earlier notes in this document used a
debug binary (430 ms/2.1 s) and overstate the release latency.
+12 -2
View File
@@ -102,6 +102,12 @@ fn project_preview_json_with_images_mode(
}
let mut document = build_document(&paragraphs, &geometry);
apply_geometry(&mut document, &geometry);
if std::env::var_os("TEXRRA_PROFILE").is_some() {
eprintln!(
"PROFILE build_done={:.1}ms",
started.elapsed().as_secs_f64() * 1000.0
);
}
let mut sessions = project_sessions()
.lock()
.map_err(|_| "route-D session lock".to_string())?;
@@ -152,7 +158,7 @@ fn project_preview_json_with_images_mode(
};
if std::env::var_os("TEXRRA_PROFILE").is_some() {
eprintln!(
"PROFILE before_render={:.1}ms",
"PROFILE layout_done={:.1}ms",
started.elapsed().as_secs_f64() * 1000.0
);
}
@@ -14460,7 +14466,11 @@ fn render_json(
let mut lists: Vec<DisplayList> = engine
.pages()
.iter()
.map(|page| {
.enumerate()
.map(|(index, page)| {
if only_pages.is_some_and(|pages| !pages.contains(&index)) {
return DisplayList::default();
}
let mut list =
page.display_list_with_layout(document.page_goal, document.text_float_sep);
list.width = list.width.max(document.paper_width);