-
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or request
Description
✨ 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. Workerstruct wraps a persistent LaTeX process with stdin/stdout handles.- Each worker:
- Accepts
.texjobs via stdin or temp files. - Emits logs and output PDFs.
- Can restart automatically on error or timeout.
- Accepts
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,
*.auxcleanup). - 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.yamlYAML Config Example:
engine:
warm:
enabled: true
poolSize: 2
idleTimeout: 60 # seconds
fmtFile: "autopdf.fmt"4. Precompiled Format Support
-
Optional
.fmtfile created via:pdflatex -ini -jobname=autopdf "&pdflatex" \input{autopdf.ltx}
-
Allows LaTeX to skip package loading on every run.
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
WorkerandWorkerPoolabstractions. - Add CLI/config integration.
- Support
.fmtpre-loading. - Write integration tests and benchmarks.
- Update README and examples.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request