๐ Tempo Performance Benchmarks โ
To ensure high performance in mass-instantiation scenarios, Tempo implements a "Zero-Cost Constructor" architecture using prototype shadowing and lazy delegation. This document outlines the benchmark results for these optimizations.
๐ Summary of Timings โ
Timings were captured over 1,000 iterations to measure micro-overhead and compare different instantiation strategies.
| Method | Total Time | ยตs / op | Notes |
|---|---|---|---|
| Default (Lazy Proxy) | 523.14ms | 523.14ยตs | Current |
| Eager Simulation | 1394.51ms | 1394.51ยตs | ~2.7x slower (simulating pre-refactor impact). |
| Fast-Fail @sync | 359.04ms | 359.04ยตs | Rejected instantly by the Master Guard. |
| Object.create Baseline | 0.22ms | 0.22ยตs | Raw JS overhead for comparison. |
๐๏ธ Architectural Impact โ
1. Proxy-Delegator Delegation ( ) โ
By using a Proxy-Delegator pattern, the constructor returns near-instantly without populating the formatting (fmt) or term (term) objects. These registries are only discovered and memoized on the first property access.
- Gain: ~65% reduction in instantiation overhead.
- v2.1.2 Update: The Scan-and-Consume guard further stabilizes the "Zero-Cost Constructor" by ensuring that even with massive plugin lists, the entry-point remains
.
2. The Master Guard (Fast-Fail) โ
The static #guard regex acts as a rapid "Sync Point."
- Efficiency: Strings that do not contain valid date-time characters are rejected in
time. - Performance: Validating a string against the guard is ~30% faster than a full parsing cycle, even for simple ISO strings.
๐งช Benchmark Methodology โ
The benchmark script used performance.now() within a Vitest environment to ensure accurate module resolution and internal alias support (#library).
- Lazy Creation: Creates a
new Tempo('2024-05-20')without accessing any properties. - Eager Simulation: Creates a
new Tempo()and manually triggers discovery on 5 core properties to simulateinitialization. - Invalid Parse: Passes a string that fails the Master Guard (e.g., includes emojis or exotic symbols) to measure rejection speed.
INFO
These benchmarks represent the library's performance under Node.js v22+. Results may vary based on the JS engine (V8, JavaScriptCore, etc.) but the