✨ Feature Request: Warm-Engine (Persistent LaTeX Worker)
Summary
Add a mode to AutoPDF in which the LaTeX engine (pdflatex, xelatex, or lualatex) remains alive and pre-loaded across multiple document builds.
This persistent (“warm”) mode avoids re-initializing packages, fonts, and macros for every render — drastically improving throughput and latency for API or batch workloads.
Motivation
Currently, each AutoPDF run spawns a new LaTeX process that performs full initialization (format load, font cache, macro expansion, hyphenation setup).
This is acceptable for ad-hoc jobs but inefficient in backend scenarios that generate many similar PDFs.
A persistent engine can:
- Eliminate redundant startup overhead.
- Reduce per-document build time from seconds to milliseconds.
- Improve scalability for services like
cartas-backend, obito-backend, or other AutoPDF clients.
Goals
- Introduce an optional warm mode:
--warm, --daemon, or via config.
- Support worker pools: one or more long-lived LaTeX subprocesses.
- Allow .fmt pre-loading for faster engine startup.
- Maintain backward compatibility (cold mode remains default).
- Provide configurable knobs: pool size, idle timeout, jobs per worker.
Scope & Deliverables
1. Worker Manager
- New module (e.g.,
internal/autopdf/worker/) managing LaTeX subprocesses.
Worker struct wraps a persistent LaTeX process with stdin/stdout handles.
- Each worker:
- Accepts
.tex jobs via stdin or temp files.
- Emits logs and output PDFs.
- Can restart automatically on error or timeout.
2. Persistent Engine Invocation
- Launch engine with
-fmt=<custom> (if provided) for faster startup.
- Keep process open between builds.
- Clean job isolation (per-job workdir,
*.aux cleanup).
- Graceful restart on crash.
3. CLI / Config Additions
autopdf build --warm \
--worker-pool-size=4 \
--worker-idle-timeout=300s \
--preload-fmt=/path/to/autopdf.fmt \
template.tex config.yaml
YAML Config Example:
engine:
warm:
enabled: true
poolSize: 2
idleTimeout: 60 # seconds
fmtFile: "autopdf.fmt"
4. Precompiled Format Support
5. Error Handling
- Capture engine stdout/stderr and exit codes.
- Restart failed workers automatically.
- Clean shutdown of idle workers.
- Optional job retry/back-off strategy.
6. Testing & Benchmarking
- Benchmark warm vs cold mode latency.
- Verify correctness (no cross-job artifacts).
- Document measurable performance gains.
Benefits
- 3–5× faster PDF generation under load.
- Predictable latency for web/API workflows.
- Lower CPU usage and I/O overhead.
- Improved competitiveness for high-volume deployments.
Risks / Considerations
- Persistent workers may accumulate memory; periodic restarts needed.
- Job isolation (e.g., leftover
.aux) must be ensured.
- Added complexity — must remain modular and optional.
Success Criteria
- Warm mode is opt-in and backward compatible.
- Multiple consecutive builds show significant latency reduction.
- Worker pool stable under parallel load.
- Clear documentation and examples.
Suggested Next Steps
- Implement
Worker and WorkerPool abstractions.
- Add CLI/config integration.
- Support
.fmt pre-loading.
- Write integration tests and benchmarks.
- Update README and examples.
✨ Feature Request: Warm-Engine (Persistent LaTeX Worker)
Summary
Add a mode to AutoPDF in which the LaTeX engine (
pdflatex,xelatex, orlualatex) remains alive and pre-loaded across multiple document builds.This persistent (“warm”) mode avoids re-initializing packages, fonts, and macros for every render — drastically improving throughput and latency for API or batch workloads.
Motivation
Currently, each AutoPDF run spawns a new LaTeX process that performs full initialization (format load, font cache, macro expansion, hyphenation setup).
This is acceptable for ad-hoc jobs but inefficient in backend scenarios that generate many similar PDFs.
A persistent engine can:
cartas-backend,obito-backend, or other AutoPDF clients.Goals
--warm,--daemon, or via config.Scope & Deliverables
1. Worker Manager
internal/autopdf/worker/) managing LaTeX subprocesses.Workerstruct wraps a persistent LaTeX process with stdin/stdout handles..texjobs via stdin or temp files.2. Persistent Engine Invocation
-fmt=<custom>(if provided) for faster startup.*.auxcleanup).3. CLI / Config Additions
YAML Config Example:
4. Precompiled Format Support
Optional
.fmtfile created via:Allows LaTeX to skip package loading on every run.
5. Error Handling
6. Testing & Benchmarking
Benefits
Risks / Considerations
.aux) must be ensured.Success Criteria
Suggested Next Steps
WorkerandWorkerPoolabstractions..fmtpre-loading.