Skip to content

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

Draft
emranemran wants to merge 7 commits intomainfrom
emran/coldstart-opt
Draft

perf(cloud): shrink fal cold start by ~20s#1024
emranemran wants to merge 7 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: 7222fbb1-5385-4e5b-acbe-9d72ed78f45d

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

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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 8d78c9d
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>
@emranemran emranemran marked this pull request as draft May 4, 2026 17:11
emranemran and others added 4 commits May 4, 2026 13:16
Two low-risk image-size reductions stacked together:

1. Switch base from `cuda:12.8.0-cudnn-runtime-ubuntu24.04` to plain
   `cuda:12.8.0-runtime-ubuntu24.04`. The pyproject.toml override
   `nvidia-cudnn-cu12>=9.15` already ships cuDNN via pip into the
   venv, so the base image's cuDNN was dead weight (~700 MB).

2. After `uv sync` and the bundled-plugin install, strip files that
   are never read at runtime: C/C++ headers/sources (only used to
   compile extensions), package tests/ and docs/ directories, .pdb
   debug symbols, and the leftover uv/apt caches. Keep .pyc /
   __pycache__ so first import isn't slowed by recompilation, and
   keep examples/ because some packages import from it.

Estimated combined savings: ~700 MB (cuDNN duplication) + 200-500 MB
(strip) = ~1 GB compressed off the 7.43 GB image.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: emranemran <emran.mah@gmail.com>
Two aggressive image-size reductions stacked:

1. Multi-stage build: build deps (curl/git/build-essential/
   software-properties-common/python3-dev) live in the builder stage
   and never reach the final image. Final stage installs only the
   runtime libs (libgl1/libglib2.0-0/libsm6/libxext6/libxrender-dev/
   libgomp1) and copies the venv + uv binary + uv-managed Python from
   the builder.

2. Strip duplicated CUDA libs from the venv. Torch on Linux brings in
   ~2 GB of nvidia-*-cu12 packages whose .so files are already in the
   base image at /usr/local/cuda/lib64. We `rm -rf` the lib dirs for
   cublas, cufft, curand, cusolver, cusparse, cuda_runtime, and
   cuda_nvrtc — keeping their dist-info so uv treats them as installed
   in the fal-side `uv sync`. LD_LIBRARY_PATH is set so torch finds
   them in /usr/local/cuda/lib64 at runtime. Kept in the venv: cuDNN
   (override-pinned newer than the base ships), cusparselt (not in
   base), nccl/cupti/nvtx/nvjitlink/nvshmem (small or version-sensitive).

Estimated combined savings: ~1.2-1.5 GB compressed off the 6.75 GB
post-base-swap image.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: emranemran <emran.mah@gmail.com>
fal's image extension runs `check_python.sh 3.12 python3.12` which
looks for python3.12 on PATH. The multi-stage rewrite dropped
python3-dev (which used to pull python3.12 into /usr/bin), causing the
deploy to fail with "the Docker image does not have a python3.12
executable". Re-add just python3.12 (the apt package, not python3-dev)
so the check passes; the actual app keeps using the uv-managed Python
from /root/.local/share/uv via uv run.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: emranemran <emran.mah@gmail.com>
After dropping curl/git from the runtime stage in the multi-stage
rewrite, fal's image-extension `install_uv.sh` failed at deploy time
with "curl is not installed". fal seems to (re)install uv even when
the image already ships one, so curl + ca-certs are mandatory.

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