Saved-state deployment choice for low-traffic SWI-Prolog service
0 reputation · 01 Sept 2020, 11:26 UTC
0 reputation · 01 Sept 2020, 11:26 UTC
Goal: minimize startup latency and resource usage for a small HTTP service by using qsave_program/2 to create a saved state and library(persistency) for fast journal reload.
Uncertainty: whether to distribute a stand-alone executable that bundles the emulator or a separate state file that relies on the system swipl binary, weighing artifact size, patch complexity, and version compatibility.
What are the trade-offs in artifact size versus update effort? How does runtime-version matching affect the feasibility of each option? Which approach better supports seamless patching of the Prolog runtime?
35275 reputation · 01 Sept 2020, 20:24 UTC
For a low-traffic SWI-Prolog HTTP service, prefer a separate saved-state file paired with a pinned system swipl binary when you control the target host. It keeps the deployed artifact small and lets the OS package manager handle runtime updates. Choose a standalone executable only when you cannot guarantee a compatible swipl on the target machine.
It is well established that qsave_program/2 produces a memory image tied to the emulator version and CPU architecture. A standalone executable bundles that image together with the emulator, producing a larger single binary. A separate state file is small but requires the host swipl to match the version used at build time.
What varies by environment is how strictly the version must match across patch releases, and whether OS-level swipl updates preserve saved-state compatibility. Treat exact patch-level compatibility as unverified until you test it in staging.
| Approach | Artifact size | Logic update | Runtime patch |
|---|---|---|---|
| Standalone executable | Large (emulator + state) | Rebuild entire binary | Rebuild entire binary |
| Separate state file | Small (state only) | Regenerate state only | OS package update, then verify state loads |
The separate-state approach better supports runtime patching because the emulator lives outside your application artifact. You can apply a distribution security update to swipl without rebuilding your Prolog code. However, if the patch changes the emulator version, the saved state will likely fail to load, forcing a regeneration. Standalone executables avoid host-version mismatch entirely, but every runtime patch requires a full rebuild of the bundled image.
swipl package version in your deployment manifest.swipl package together.swipl build in a staging environment.Do you control the target host's swipl installation, or must the artifact be fully self-contained? If you control the host, the separate state file is usually the better fit for a low-traffic service. If you do not, a standalone executable is safer despite the larger artifact and heavier rebuild cycle.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.