Serialise only changed pages for patch previews
render_json now accepts an optional page whitelist. The new project_preview_patch_json_with_images path passes changedPages before building page SVGs, instead of serialising all pages and filtering afterwards in the server. Cache hits still use the old filter helper. Add scripts/bench-preview.py: repeated buffer edits against a running server, reporting HTTP/server latency, bytes and changedPages. Measure release builds: article-basic 37.5 ms (one page), arXiv late edit p50 199 ms / p95 222 ms with one changed page at 175 KB, arXiv heading edit ~480 ms. This is a solid improvement over the debug numbers previously quoted, but the 10-page <100 ms target remains unmet. TEXRRA_PROFILE=1 now gates the geometry/paragraph/before-render timings. Test count is 1073 (67 server).
This commit is contained in:
1 parent
9231c3a7d6
commit
d124c646a1
4 files changed
+162
-14
No files matched your search
Executable
+84
@@ -0,0 +1,84 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Measure warm dirty-page preview latency against a running texrra server.
|
||||
|
||||
The server must already be serving the project. The script sends the editor
|
||||
buffer, forces a small text edit each iteration, and reports the HTTP latency,
|
||||
server duration and patch size.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import statistics
|
||||
import time
|
||||
import urllib.request
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def request(base, project, source, patch):
|
||||
suffix = "&patch=1" if patch else ""
|
||||
req = urllib.request.Request(
|
||||
f"{base}/api/projects/{project}/preview?engine=route-d&buffer=1{suffix}",
|
||||
data=source.encode("utf-8"),
|
||||
headers={"Content-Type": "text/plain; charset=utf-8"},
|
||||
method="POST",
|
||||
)
|
||||
started = time.perf_counter()
|
||||
with urllib.request.urlopen(req, timeout=120) as response:
|
||||
body = response.read()
|
||||
return (time.perf_counter() - started) * 1000.0, body
|
||||
|
||||
|
||||
def percentile(values, fraction):
|
||||
ordered = sorted(values)
|
||||
index = min(len(ordered) - 1, max(0, round(fraction * (len(ordered) - 1))))
|
||||
return ordered[index]
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--base", default="http://127.0.0.1:4173")
|
||||
parser.add_argument("--project", required=True)
|
||||
parser.add_argument("--source", required=True, type=Path)
|
||||
parser.add_argument("--needle", required=True)
|
||||
parser.add_argument("--replacement", default="edited")
|
||||
parser.add_argument("--iterations", type=int, default=10)
|
||||
args = parser.parse_args()
|
||||
|
||||
source = args.source.read_text(encoding="utf-8")
|
||||
if args.needle not in source:
|
||||
raise SystemExit(f"needle not found in {args.source}: {args.needle!r}")
|
||||
|
||||
elapsed, initial = request(args.base, args.project, source, False)
|
||||
print(f"initial full: {elapsed:.1f} ms, {len(initial)} bytes")
|
||||
|
||||
latencies = []
|
||||
durations = []
|
||||
sizes = []
|
||||
changed = []
|
||||
for index in range(args.iterations):
|
||||
edited = source.replace(
|
||||
args.needle, f"{args.needle} {args.replacement}{index}", 1
|
||||
)
|
||||
elapsed, body = request(args.base, args.project, edited, True)
|
||||
payload = json.loads(body)
|
||||
latencies.append(elapsed)
|
||||
durations.append(payload.get("durationMs", 0.0))
|
||||
sizes.append(len(body))
|
||||
changed.append(len(payload.get("changedPages", [])))
|
||||
print(
|
||||
f"edit {index + 1}: http={elapsed:.1f} ms "
|
||||
f"server={payload.get('durationMs', 0.0):.1f} ms "
|
||||
f"bytes={len(body)} changed={payload.get('changedPages')}"
|
||||
)
|
||||
|
||||
print(
|
||||
"summary: "
|
||||
f"p50_http={statistics.median(latencies):.1f} ms "
|
||||
f"p95_http={percentile(latencies, 0.95):.1f} ms "
|
||||
f"p50_server={statistics.median(durations):.1f} ms "
|
||||
f"pages_changed={changed}"
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user