Skip to content

perf(cloud): shrink fal cold start by ~20s#1024

Open
emranemran wants to merge 3 commits intomainfrom
emran/coldstart-opt
Open

perf(cloud): shrink fal cold start by ~20s#1024
emranemran wants to merge 3 commits intomainfrom
emran/coldstart-opt

Conversation

@emranemran
Copy link
Copy Markdown
Contributor

Summary

Three changes to the fal cold-start path, derived from a real cold-start trace in fal.log:

  • livepeer_fal_app.py: drop requirements = [...] so fal isolate stops provisioning a separate venv on top of the image's. Combined with the Dockerfile change below, removes the ~10–12s Downloaded transformers / Uninstalled 50 packages / Installed 56 packages block visible on every cold start.
  • Dockerfile.cloud: pre-build the venv with uv sync --extra livepeer --extra kafka --no-dev so the runtime uv run --extra livepeer --extra kafka livepeer-runner is a no-op.
  • livepeer_fal_app.py dockerfile_str: re-sync after COPY src/ so the daydream-scope editable install is refreshed at image build time (kills the Built daydream-scope @ file:///app rebuild on every cold start).
  • livepeer_app.py lifespan: pre-warm the pipeline registry so the torch/diffusers/transformers/torchao import cascade runs at runner startup instead of on the first cloud-proxy call (~8s shifted off the user-perceived connect path).

Combined expected savings: ~20s of user-visible cold start.

Test plan

  • uv run ruff check src/scope/cloud/livepeer_app.py src/scope/cloud/livepeer_fal_app.py — clean
  • uv run ruff format --check — already formatted
  • Both files compile (py_compile)
  • fal SDK loads livepeer_fal_app.py and reports requirements = []
  • Deploy to scope-livepeer-emran, force a cold start, capture runner logs, compare phase deltas vs the baseline fal.log. The "Downloaded / Uninstalled / Installed" block should be gone, and Registry initialized should fire before the first WS handshake.

🤖 Generated with Claude Code

emranemran and others added 2 commits May 1, 2026 09:48
Three changes that target the cold-start path measured in fal.log:

- livepeer_fal_app.py: drop `requirements = [...]` so fal isolate stops
  provisioning a separate venv on top of the image's. The image already
  has websockets/httpx/aiokafka via the kafka extra below.
- Dockerfile.cloud: pre-build the venv with `uv sync --extra livepeer
  --extra kafka --no-dev` so the runtime `uv run --extra livepeer
  --extra kafka livepeer-runner` is a no-op instead of fetching +
  installing aiokafka, uvloop, and re-resolving ~50 packages.
- livepeer_fal_app.py dockerfile_str: re-sync after `COPY src/` so the
  daydream-scope editable install is refreshed at image build time,
  eliminating the "Built daydream-scope @ file:///app" rebuild on every
  cold start.
- livepeer_app.py lifespan: pre-warm the pipeline registry so the
  torch/diffusers/transformers/torchao import cascade runs at runner
  startup instead of on the first cloud-proxy call (~8s shifted off
  the user-perceived connect path).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: emranemran <emran.mah@gmail.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 1, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b564b16f-3685-4fc9-85ad-57e3bbd29b8d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch emran/coldstart-opt

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

🚀 fal.ai Preview Deployment

Commit 1f94168
App ID daydream/scope-livepeer-pr-1024--preview
WebSocket wss://fal.run/daydream/scope-livepeer-pr-1024--preview/ws

Testing on Cloud

SCOPE_CLOUD_APP_ID="daydream/scope-livepeer-pr-1024--preview/ws" uv run daydream-scope

Empty `requirements` broke the wrapper at first websocket — fal isolate
runs the App's setup() / websocket handler in a venv separate from the
image's /app/.venv (under /usr/local/lib/python3.12/dist-packages),
where httpx wasn't available, so check_runner_readiness raised
ModuleNotFoundError on every connect.

The ~10s cold-start tax that motivated emptying requirements was
actually `uv run --extra livepeer --extra kafka` resyncing the image
venv, not isolate. The Dockerfile.cloud `uv sync --extra livepeer
--extra kafka --no-dev` and the fal-side dockerfile_str re-sync from
the previous commit already address that on their own.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: emranemran <emran.mah@gmail.com>
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.

1 participant