Performance Benchmarks
Relevant source files
The following files were used as context for generating this wiki page:
Performance Benchmarks evaluate the efficiency of the nuxt-i18n-micro module against baseline Nuxt implementations and alternative i18n solutions. The system measures build duration, bundle size, runtime execution speed, and server load capacity using automated scripts and specialized testing tools.
The benchmarking suite provides quantifiable data on how the module handles large-scale translation dictionaries and complex routing strategies. It ensures that new features do not introduce regressions in speed or resource consumption.
Benchmarking Architecture
The performance testing infrastructure consists of three main components: unit-level execution benchmarks, integration-level build/load tests, and payload budget monitoring.
The diagram above illustrates the flow from the CLI command to the final generation of performance reports and charts.
Sources: scripts/src/commands/performance.ts:1-74, scripts/src/perf/report.ts:98-144
Test Execution Flow
The benchmarking process follows a strict sequence to ensure data accuracy:
- Environment Setup: Clears existing artifacts and settles the system.
- Build Phase: Executes
nuxi buildfor specific fixtures (plain-nuxt, i18n-micro, @nuxtjs/i18n). - Cool-down: Implements delays (e.g., 2s post-build, 5s between fixtures) to prevent thermal throttling or resource contention.
- Load Phase: Spawns the Nitro server and runs Artillery for traffic simulation.
- Reporting: Calculates means across multiple runs and generates comparison charts.
Sources: scripts/src/perf/report.ts:401-412, scripts/src/perf/config.ts:41-52
Core Runtime Benchmarks
Runtime benchmarks measure the micro-performance of internal functions within @i18n-micro/core. Tests run for thousands of iterations (e.g., 50,000) to calculate operations per millisecond (ops/ms).
Measured Metrics
| Component | Function | Description |
|---|---|---|
| BaseI18n | t() | Translation lookup for flat and nested keys. |
| Helpers | interpolate() | String replacement speed for translation parameters. |
| FormatService | formatNumber() | Performance of Intl-based number formatting. |
| Translation | getTranslation() | Speed of retrieving values from the internal translation storage. |
Sources: packages/core/tests/perf-benchmark.test.ts:223-317
Regression Detection
The system compares current results against a stored baseline.json. A test fails if performance drops below a specific threshold:
- Standard: 15% drop.
- High Performance: 25-30% drop for functions exceeding 5,000 ops/ms.
Sources: packages/core/tests/perf-benchmark.test.ts:25-30, packages/core/tests/perf-benchmark.test.ts:92-97
Load and Throughput Testing
Load testing utilizes Artillery to simulate high-concurrency environments. It measures how the localized Nitro server handles Virtual Users (VUs) and concurrent requests.
The sequence diagram shows the interaction between the performance runner, the target server, and the Artillery load generator.
Sources: scripts/src/perf/load.ts:1-100, scripts/src/commands/payload-budget.ts:95-120
Load Metrics
- Requests Per Second (RPS): The total throughput the server sustains.
- Latency Percentiles: Measured at P50, P95, and P99 to identify tail latency issues.
- Error Rate: Percentage of failed requests during the load window.
- Resource Usage: Peak and average CPU/RSS memory consumption during load.
Sources: scripts/src/perf/report.ts:225-235, scripts/src/perf/charts.ts:291-310
Payload Budgeting
Payload budgeting prevents "bloat" in the client-side hydration payload. The system measures the size of the __NUXT_DATA__ script tag in the rendered HTML, as this carries the translations to the browser.
Budget Targets
- maxNuxtData: The maximum size of the hydration payload allowed for a single route.
- totalNuxtData: The cumulative size across all measured routes.
- clientAssets: Total size of JS and CSS files in the
.output/publicdirectory. - payloadFiles: Size of external translation JSON files served via the API.
Sources: scripts/src/commands/payload-budget.ts:15-35, scripts/src/commands/payload-budget.ts:203-215
Budget Enforcement
The system calculates limits with a configurable tolerance (default 10%). If the current build exceeds these limits, the CI process fails. This ensures that changes to the dictionary injection logic do not inadvertently inline large translation sets into every HTML page.
Sources: scripts/src/commands/payload-budget.ts:175-185, scripts/src/commands/payload-budget.ts:220-225
Reporting and Visualization
The benchmarking suite generates a comprehensive performance-results.md file containing tables and embedded Chart.js configurations.
Visualization Types
- Build Time Comparison: Bar charts comparing seconds to build each fixture.
- Bundle Size Analysis: Stacked bar charts showing Code vs. Translations.
- Latency Distribution: Charts showing P95 latency over the duration of the load test.
- Throughput Summary: Comparison of RPS across different i18n strategies.
Sources: scripts/src/perf/report.ts:250-290, scripts/src/perf/charts.ts:380-415
Profile Configurations
Benchmarking uses specific profiles to simulate real-world usage:
- Default: 4 locales, 10,000 leaf keys per locale.
- Tree Depth: Fixed at 5 levels to simulate realistic nested dictionary structures.
- Load Profiles:
short(fast verification) vsfull(standard for documentation).
Sources: scripts/src/perf/config.ts:31-40, scripts/src/perf/config.ts:79-88
The performance benchmarking system ensures that nuxt-i18n-micro remains a high-performance alternative for Nuxt applications, prioritizing low build times and minimal runtime overhead even as translation complexity increases.