Performance & Resource Usage
Lila is tuned for small VPS servers: few MB of RAM, low CPU per request and no build tooling. Most optimizations are automatic; the checklist below shows the few you run yourself.
Production checklist
lila css build # compiled Tailwind CSS instead of the 270 KB browser runtime
lila optimize # minified JS/CSS + .gz/.br files + WebP images
lila doctor # validates .env, translations, compiled CSS...
lila run -w 1 # or: lila run --server granian
1. Compiled Tailwind CSS (lila css build)
In development every page loads the Tailwind browser runtime (instant, no build). For production lila css build downloads the official standalone Tailwind binary once (no Node.js; cached per version in ~/.cache/lila/tailwind and verified against the release sha256sums.txt), scans your templates, app/, public/js and Lila's own templates/scripts, and writes a minified public/css/lila.css plus .gz/.br.
lila css build # one-off build (run it before every deploy)
lila css build --watch # rebuild while you edit
lila css clean # remove it (pages go back to the runtime)
TAILWIND_BIN=/usr/local/bin/tailwindcss lila css build # use an existing binary
TAILWIND_MODE=auto(default): compiled CSS when it exists andDEBUG=False, runtime in debug.TAILWIND_MODE=build: always the compiled file;play: always the runtime.- Your own CSS goes in
resources/css/app.css(included in the build). - Classes built dynamically in JS must appear as full strings somewhere in the scanned files.
2. Static files compressed once
.br/.gzfiles next to the original (fromlila optimizeorlila css build) are served directly when the browser accepts them.- Other text assets (JS, CSS, SVG, JSON) are compressed once and kept in a small in-memory LRU; images and fonts are never recompressed.
- The global GZip middleware skips static paths and uses level 5 for dynamic pages (≈2–3× less CPU than level 9, ≈+18% req/s on HTML pages measured).
/js/lila-client.jsand/js/ws.jsare minified (rjsmin) and compressed: 94 KB → 19 KB transferred.
3. ETag / 304 for pages and APIs
App(etag=True) (default) adds a weak ETag to HTML/JSON GET responses. When the content did not change the browser receives an empty 304 Not Modified. Streams, SSE and files are not touched.
4. Memory budget for the cache
The memory cache is limited by items and approximate size: CACHE_MAX_MB=64 (default). Expired entries go first, then the oldest non-session entries; sessions are evicted last. Cache.stats() reports memory_mb.
5. Faster model reads
get_all_async, get_by_id_async and paginate_async use SQLAlchemy Core and return dicts directly (≈1.8× faster for 1000 rows than building ORM objects) and never read __private_fields__. On SQLite, writes from one process are queued behind a lock (SQLite has a single writer) so bursts do not fail with "database is locked"; reads stay concurrent (WAL). PRAGMA optimize runs on shutdown.
6. Templates
Compiled Jinja templates are cached on disk in production (app/cache/jinja, disable with JINJA_BYTECODE_CACHE=false): new workers start faster.
7. Server choice and measuring
pip install granian
lila run --server granian -w 2 --max-rss 300 # Rust server; restarts a worker above 300 MB
# or in .env: LILA_SERVER=granian
lila bench http://127.0.0.1:8000/ -c 50 -d 10 --pid <server pid>
lila bench is a dependency-free keep-alive HTTP load generator: requests/s, p50/p95/p99 latency, status codes and the server RSS. Remember that the global rate_limit (300 req/min per IP by default) answers 429 to a benchmark from one IP; disable it while measuring.
8. Disk
- Logs older than
LOG_RETENTION_DAYS(default 30) are removed on startup. lila backup --compressstores.sqlite.gzbackups (3–10× smaller).- Finished tasks are pruned after
TASK_KEEP_DONE_HOURS(24).