Skip to content

Web app starts in ~7 s instead of ~11 s; first plot ~4 s sooner (D4.1) - #51

Merged
NCCU-Schultz-Lab merged 1 commit into
mainfrom
claude/d4-startup
Nov 6, 2026
Merged

NCCU-Schultz-Lab merged 1 commit into
mainfrom
claude/d4-startup

Conversation

@NCCU-Schultz-Lab

@NCCU-Schultz-Lab NCCU-Schultz-Lab commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

This is roadmap D4.1. I measured where the browser app's start-up goes, then cut the two biggest costs.

Measuring

  • index.html keeps a start-up timeline in window.eaglePlotBootLog: each stlite progress message, loadFinished and "ready".
  • scripts/web/boot_timing.js loads the app in a fresh browser profile (a first visit), then reloads with the cache kept (a warm visit). It prints the timeline and the bytes downloaded, including what the Python worker fetches. --throttle emulates a slower network.
  • docs.yml now runs it after the smoke test, against the real Pyodide CDN, and writes the result to the job summary. It doesn't gate.

Before, measured locally with self-hosted Pyodide (no network):

Stage Time
Loading Pyodide 1.5 s
Installing packages 5.4 s, of which scipy alone is ~2.2 s
Loading Streamlit 1.0 s
Home.py 2.8 s, of which import pandas is 2.3 s

What changed

  • scipy loads after the app appears. Home starts loading it in the background (runtime.DEFERRED_PACKAGES).
    • A page that imports scipy shows "Loading the science libraries…" until the load has finished, then reruns by itself. Home and Quick Plot don't wait.
    • Readiness comes from the settled load promise, not find_spec. In testing, scipy's files were found before its compiled modules were loaded, and the page failed with "dynamic module does not define module export function".
  • Home no longer imports pandas. eagleplot.utils loads its submodules on first use (PEP 562), and session_state imports numpy and pandas only inside the functions that use them.
  • Background warm-up. Once Home is drawn, pandas, matplotlib and the plotting modules are imported one per event-loop turn, so a click is handled between two imports.
  • eagleplot.plotting imports seaborn and plotly on first use. HAS_SEABORN and HAS_PLOTLY now come from find_spec, so a Matplotlib plot loads neither, nor scipy. This also speeds up the installed GUI slightly.

Results (local, self-hosted Pyodide)

Before After
App ready 11.4 s 7.2 s
Open the app, then click "Plot this example" at once: time to plot ~16.4 s 12.3 s
Click → plot after reading Home for 3 s – 2.4 s

Download size: a cold start transfers about 64 MB compressed. 14 MB of that is scipy, which now loads after "ready". The biggest remaining items are pyarrow (10 MB, needed by Streamlit) and plotly (10 MB). Deferring plotly is the next step: Streamlit only registers its plotly theme when Streamlit starts, so that needs separate handling.

Tests

  • New tests/test_web_build.py covers:
    • the deferred load (started once, and nothing on a server)
    • a half-loaded package counting as missing
    • Data Upload waiting while scipy loads, and Quick Plot not waiting
    • Home's imports not loading pandas
    • eagleplot.plotting not loading seaborn, plotly or scipy
  • Full suite: Python 3.13: 1269 passed. Python 3.9: 1261 passed.
  • ruff check and format are clean.
  • Browser build (self-hosted Pyodide): scripts/web/smoke.js passes, with 32 page loads including Data Upload right after start-up, the splash steps and the on-click download.

🤖 Generated with Claude Code

Measured the start-up (scripts/web/boot_timing.js, a timeline from stlite's
progress events now kept in window.eaglePlotBootLog) and cut the two big
costs, locally with self-hosted Pyodide:

- scipy is no longer loaded at start-up (it alone added ~2 s). Home starts
  loading it in the background (runtime.DEFERRED_PACKAGES); pages that
  import it show "Loading the science libraries..." until the load has
  settled (a settled promise, not find_spec: half-loaded scipy failed with
  "dynamic module does not define module export function"). Home and
  Quick Plot don't wait.
- Home no longer imports pandas (~2.3 s under Pyodide): eagleplot.utils
  loads its submodules on first use (PEP 562) and session_state imports
  numpy/pandas where used. After Home is drawn, pandas, matplotlib and the
  plotting modules are imported in the background, one per loop turn.
- eagleplot.plotting imports seaborn and plotly on first use (HAS_SEABORN /
  HAS_PLOTLY via find_spec), so a Matplotlib plot needs neither, nor scipy.

Ready: 11.4 s -> 7.2 s. Home -> "Plot this example" -> plot, clicked at
once: ~16.4 s -> 12.3 s from opening the app.

docs.yml reports the start-up timeline with the real CDN on every run
(non-gating). Tests: tests/test_web_build.py (deferred load, the waiting
page, Quick Plot not waiting, no pandas in Home's imports, no seaborn/
plotly/scipy in eagleplot.plotting's).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@NCCU-Schultz-Lab
NCCU-Schultz-Lab merged commit 136c543 into main Nov 6, 2026
9 checks passed
@NCCU-Schultz-Lab NCCU-Schultz-Lab mentioned this pull request Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants