Skip to content

Resource Consumption

Terranova is designed for efficiency and low resource consumption. From the binary size to request handling, each component is chosen or implemented with performance in mind.

Metric Typical Value Notes
Memory usage (idle) < 1 MB Depends on project specification (number of entities, queries, etc.).
CPU usage (idle) 0% No background polling; completely idle when no requests are served.

Terranova is suitable for constrained environments such as embedded systems, edge devices, or low‑cost VPS instances.


Request Handling Pipeline

1. JSON Parsing – yyjson

All JSON parsing (request bodies, API responses) is handled by yyjson, a high‑performance JSON library written in C. It offers:

  • Fast, low‑latency parsing and serialization.
  • Zero‑copy reads where possible.
  • Small memory footprint.

2. Query Execution – Prepared Statements

SQL queries are prepared once at startup. Parameters are bound and statements executed per request with minimal overhead.

3. Template Rendering – mch

Terranova includes an internal Mustache engine named mch. The rendering process:

  1. Compilation – The template source string is compiled into bytecode at startup (or when the template is first loaded).
  2. Execution – On each request, the bytecode is interpreted against the data context.
  3. Future plans – A JIT compiler is planned to further reduce latency.

Even without JIT, mch is fast enough for typical web applications.

4. HTTP Handlers – JIT Compilation with TCC

To minimize per‑request latency, Terranova uses TCC (Tiny C Compiler) to just‑in‑time compile request handlers.

  • Handlers are generated from the specification and compiled to machine code at startup.
  • The compiled code runs with near‑native speed, eliminating interpreter overhead.

Latency Benchmarks

For typical small test cases (simple queries, small templates), response times range from 1 to 3 milliseconds.

Note: A comprehensive benchmark suite is planned. The numbers above are based on early internal testing and may vary depending on hardware and workload.


Efficiency Principles

  • No unnecessary allocations – Reuses buffers and prepared statements across requests.
  • Zero‑copy where possible – Especially in JSON and static file serving.
  • Idle without polling – No background threads or timers when not handling requests.
  • Compile‑time optimization – Much of the request handling logic is generated and compiled ahead‑of‑time (or JIT), not interpreted.

See Also