perf: Chromium 启动 flag 微调 + screencast 画质 q60->q50
Flag:加 --no-first-run、--no-default-browser-check、 --disable-default-apps、--disable-extensions、 --disable-background-networking、--disable-sync、 --disable-translate,只跳过首跑/装配活,不改渲染与工具 行为。实测(runsc 容器,launch + new_page,各 3 次交替): 旧中位数 0.889s、新 0.819s——只差 70ms 且在逐次噪声 (0.70-0.99s)里,几百毫秒的预期不成立;零成本顺手留着。 画质:screencast 与 eager 抓帧 q60 -> q50,分辨率 1280x800 不动,点击坐标系不受影响。实测同页文本+渐变: 62068 -> 56428 字节(-9%),不是经验法则的 30%;觉得糊 一句话改回 60。
This commit is contained in:
1 parent
878f8de7da
commit
56b8f98b47
2 files changed
+29
-5
No files matched your search
@@ -83,9 +83,23 @@ class Browser:
|
|||||||
else:
|
else:
|
||||||
from playwright.sync_api import sync_playwright
|
from playwright.sync_api import sync_playwright
|
||||||
pw = sync_playwright().start()
|
pw = sync_playwright().start()
|
||||||
|
# Extra flags skip first-run/setup work only; they
|
||||||
|
# change nothing about page rendering or tool
|
||||||
|
# behaviour. Measured 2026-10-30 (runsc container,
|
||||||
|
# launch + new_page, 3 runs each, alternating):
|
||||||
|
# old median 0.889s, new median 0.819s -- ~70ms,
|
||||||
|
# inside run-to-run noise (0.70-0.99s either way).
|
||||||
|
# Kept anyway: zero cost, directionally faster.
|
||||||
launch = {"args": ["--no-sandbox",
|
launch = {"args": ["--no-sandbox",
|
||||||
"--disable-dev-shm-usage",
|
"--disable-dev-shm-usage",
|
||||||
"--disable-gpu"]}
|
"--disable-gpu",
|
||||||
|
"--no-first-run",
|
||||||
|
"--no-default-browser-check",
|
||||||
|
"--disable-default-apps",
|
||||||
|
"--disable-extensions",
|
||||||
|
"--disable-background-networking",
|
||||||
|
"--disable-sync",
|
||||||
|
"--disable-translate"]}
|
||||||
if self.proxy:
|
if self.proxy:
|
||||||
launch["proxy"] = {"server": self.proxy}
|
launch["proxy"] = {"server": self.proxy}
|
||||||
browser = pw.chromium.launch(**launch)
|
browser = pw.chromium.launch(**launch)
|
||||||
@@ -318,8 +332,13 @@ class Browser:
|
|||||||
# bytes), so dropping the frame-skip buys
|
# bytes), so dropping the frame-skip buys
|
||||||
# responsiveness exactly when it matters -- scrolling,
|
# responsiveness exactly when it matters -- scrolling,
|
||||||
# dragging, animation -- without a static-page tax.
|
# dragging, animation -- without a static-page tax.
|
||||||
|
# quality 50 (was 60): measured 2026-10-30 on a
|
||||||
|
# text+gradient page, 62068 -> 56428 bytes (-9%).
|
||||||
|
# Less than the 30% rule of thumb, but free: same
|
||||||
|
# 1280x800 pixels, so click coordinates are
|
||||||
|
# unaffected. Revert to 60 if text looks soft.
|
||||||
cdp.send("Page.startScreencast",
|
cdp.send("Page.startScreencast",
|
||||||
{"format": "jpeg", "quality": 60,
|
{"format": "jpeg", "quality": 50,
|
||||||
"maxWidth": 1280, "maxHeight": 800,
|
"maxWidth": 1280, "maxHeight": 800,
|
||||||
"everyNthFrame": 1})
|
"everyNthFrame": 1})
|
||||||
self._cdp = cdp
|
self._cdp = cdp
|
||||||
@@ -343,7 +362,7 @@ class Browser:
|
|||||||
try:
|
try:
|
||||||
result = self._cdp.send(
|
result = self._cdp.send(
|
||||||
"Page.captureScreenshot",
|
"Page.captureScreenshot",
|
||||||
{"format": "jpeg", "quality": 60})
|
{"format": "jpeg", "quality": 50})
|
||||||
data = result.get("data") if isinstance(result, dict) \
|
data = result.get("data") if isinstance(result, dict) \
|
||||||
else None
|
else None
|
||||||
if data:
|
if data:
|
||||||
|
|||||||
@@ -180,6 +180,11 @@ class BrowserTest(unittest.TestCase):
|
|||||||
{"server": "http://proxy:8888"})
|
{"server": "http://proxy:8888"})
|
||||||
self.assertIn("--no-sandbox",
|
self.assertIn("--no-sandbox",
|
||||||
self.browser._pw.launch_kwargs["args"])
|
self.browser._pw.launch_kwargs["args"])
|
||||||
|
for flag in ("--no-first-run", "--no-default-browser-check",
|
||||||
|
"--disable-default-apps", "--disable-extensions",
|
||||||
|
"--disable-background-networking", "--disable-sync",
|
||||||
|
"--disable-translate"):
|
||||||
|
self.assertIn(flag, self.browser._pw.launch_kwargs["args"])
|
||||||
|
|
||||||
def test_snapshot_truncates_with_flag(self):
|
def test_snapshot_truncates_with_flag(self):
|
||||||
self.browser.navigate("https://example.com")
|
self.browser.navigate("https://example.com")
|
||||||
@@ -254,7 +259,7 @@ class BrowserTest(unittest.TestCase):
|
|||||||
self.browser.set_frame_sink(sink)
|
self.browser.set_frame_sink(sink)
|
||||||
self.browser.navigate("https://example.com")
|
self.browser.navigate("https://example.com")
|
||||||
self.assertIn(("Page.startScreencast",
|
self.assertIn(("Page.startScreencast",
|
||||||
{"format": "jpeg", "quality": 60,
|
{"format": "jpeg", "quality": 50,
|
||||||
"maxWidth": 1280, "maxHeight": 800,
|
"maxWidth": 1280, "maxHeight": 800,
|
||||||
"everyNthFrame": 1}),
|
"everyNthFrame": 1}),
|
||||||
[(m, p) for m, p in self.page.cdp.sent])
|
[(m, p) for m, p in self.page.cdp.sent])
|
||||||
@@ -272,7 +277,7 @@ class BrowserTest(unittest.TestCase):
|
|||||||
result = self.browser.navigate("https://example.com")
|
result = self.browser.navigate("https://example.com")
|
||||||
self.assertTrue(result["ok"])
|
self.assertTrue(result["ok"])
|
||||||
self.assertIn(("Page.captureScreenshot",
|
self.assertIn(("Page.captureScreenshot",
|
||||||
{"format": "jpeg", "quality": 60}),
|
{"format": "jpeg", "quality": 50}),
|
||||||
[(m, p) for m, p in self.page.cdp.sent])
|
[(m, p) for m, p in self.page.cdp.sent])
|
||||||
frame = self.browser.pump_screencast()
|
frame = self.browser.pump_screencast()
|
||||||
self.assertEqual(frame, "EAGERDATA")
|
self.assertEqual(frame, "EAGERDATA")
|
||||||
|
|||||||
Reference in new issue
Block a user