perf: parallelize mobile workspace fetch (Closes #1116)
Some checks failed
CI / lint (pull_request) Successful in 2m50s
CI / build-release (pull_request) Successful in 6s
CI / browser-journey (pull_request) Failing after 2m56s
CI / release-candidate (pull_request) Has been skipped

This commit is contained in:
timmy 2026-08-19 06:24:52 +00:00
parent d054cd23ed
commit 950d52d147
3 changed files with 47 additions and 4 deletions

View File

@ -114,7 +114,13 @@ def build_frontend(frontend_dir: Path) -> FrontendBuild:
f'<meta name="stackchain-feature-{name}" content="{bundle.runtime_name}">'
for name, bundle in feature_bundles.items()
)
dashboard_html = dashboard_html.replace("</head>", feature_metadata + "\n</head>")
workspace_preload = (
f'<link rel="preload" as="script" '
f'href="{feature_bundles["today-timer"].runtime_name}">'
)
dashboard_html = dashboard_html.replace(
"</head>", feature_metadata + "\n" + workspace_preload + "\n</head>"
)
dashboard_html = dashboard_html.replace(
"</body>",
f'<script src="{core.runtime_name}"></script>\n</body>',

View File

@ -29,6 +29,7 @@ def test_release_artifact_bootstraps_mobile_home_and_returns_from_insights(
browser_errors: list[str] = []
failed_responses: list[str] = []
workspace_requests: list[str] = []
launch_transfer_events: list[str] = []
live_requests: list[str] = []
try:
@ -38,6 +39,18 @@ def test_release_artifact_bootstraps_mobile_home_and_returns_from_insights(
viewport={"width": width, "height": height}, ignore_https_errors=True
)
page = context.new_page()
cdp = context.new_cdp_session(page)
cdp.send("Network.enable")
cdp.send(
"Network.emulateNetworkConditions",
{
"offline": False,
"latency": 100,
"downloadThroughput": 48 * 1024,
"uploadThroughput": 48 * 1024,
"connectionType": "cellular3g",
},
)
page.on("pageerror", lambda error: browser_errors.append(error.stack or str(error)))
page.on(
"console",
@ -53,9 +66,16 @@ def test_release_artifact_bootstraps_mobile_home_and_returns_from_insights(
)
page.on(
"request",
lambda request: workspace_requests.append(request.url)
if "feature-today-timer-" in request.url
else None,
lambda request: (
workspace_requests.append(request.url),
launch_transfer_events.append("workspace-requested"),
)
if "feature-today-timer-" in request.url else None,
)
page.on(
"requestfinished",
lambda request: launch_transfer_events.append("core-finished")
if "/runtime-" in request.url else None,
)
page.on(
"request",
@ -69,6 +89,9 @@ def test_release_artifact_bootstraps_mobile_home_and_returns_from_insights(
page.locator('input[name="access_token"]').fill(ACCESS_TOKEN)
page.locator("#submit-sign-in").click()
page.wait_for_url(origin + "/", wait_until="networkidle")
assert launch_transfer_events.index("workspace-requested") < (
launch_transfer_events.index("core-finished")
), launch_transfer_events
expect(page.locator("#my-work-status")).to_contain_text("2")
initial_live_requests = len(live_requests)

View File

@ -15,6 +15,7 @@ from src.views import dashboard, feature_bundle, runtime_bundle, service_worker
FRONTEND = Path(__file__).resolve().parents[1] / "frontend"
PAGE_SCRIPT = re.compile(r'<script src="(static/[^"]+\.js)"></script>')
SCRIPT_PRELOAD = re.compile(r'<link rel="preload" as="script" href="([^"]+)">')
def test_page_runtime_is_one_deterministic_content_addressed_bundle(tmp_path):
@ -119,6 +120,19 @@ def test_product_workflows_are_stable_lazy_feature_chunks(tmp_path):
assert security_changed.feature_bundles["security-center"].runtime_name != security_center.runtime_name
def test_mandatory_workspace_fetch_is_preloaded_without_blocking_launch():
build = build_frontend(FRONTEND)
workspace = build.feature_bundles["today-timer"]
assert SCRIPT_PRELOAD.findall(build.dashboard_html) == [workspace.runtime_name]
assert build.dashboard_html.count(f'<script src="{workspace.runtime_name}"></script>') == 0
assert len(build.runtime_gzip_bytes) <= 100 * 1024
assert len(workspace.runtime_gzip_bytes) <= 110 * 1024
shell_block = build.service_worker_source.split("const OPTIONAL_FEATURES = [", 1)[0]
assert f"BASE + '{workspace.runtime_name}'" not in shell_block
def test_shipped_browser_bundles_are_valid_javascript(tmp_path):
build = build_frontend(FRONTEND)
bundles = {"core.js": build.runtime_bytes}