Back to Langflow

Pre-warm LFX with lfx prewarm

docs/versioned_docs/version-1.11.0/Lfx/lfx-prewarm.mdx

1.12.0.dev32.0 KB
Original Source

lfx prewarm pre-warms core component imports and, optionally, specific flows so the first build or run after a fork or snapshot skips the cold lazy-import cost.

:::tip lfx prewarm has no benefit for single-shot lfx run invocations. Use it in a long-lived process when you intend to fork workers or capture a warm snapshot. :::

Prewarming works in two layers:

Core import warm-up imports the built-in component classes and runs a small flow with no network or threads to prime the graph execution machinery.

Flow warm-up builds or fully executes a specific flow JSON to maximize warmth for that flow.

Performance

The table below shows measured timings for a simple flow in a completely fresh environment with no cached imports.

PhaseCold (median)Prewarmed (median)Speedup
Import4448 ms5.6 ms790×
Build260 ms58 ms
Run2.6 ms1.9 ms~1×
Total per request4709 ms66 ms71×

These numbers represent the upper bound of what prewarming can deliver. Flows that use components with non-core imports will still incur those import costs on first execution, reducing the effective speedup.

lfx prewarm commands

bash
# Warm core imports only
lfx prewarm

# Warm core imports and a specific flow
lfx prewarm --flow my-flow.json

# Warm and freeze the heap for copy-on-write sharing across forks
lfx prewarm --freeze

Options

OptionDescription
--flowPath to a flow JSON file to warm. Can be repeated for multiple flows.
--freezeCall gc.freeze() after warming to enable copy-on-write heap sharing across forks.
--skip-runSkip the hermetic warm-up run (imports only).
--unsafe-run-may-leak-connectionsFully execute each --flow (maximum warmth). Leaves live connections and is not fork-safe.
--verbosePrint per-component import results and timing.

See also