| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent deed5d8 commit 33e6d5f
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,6 +7,7 @@ | |||
| 7 | 7 | */ | |
| 8 | 8 | ||
| 9 | 9 | import fs from 'node:fs'; | |
| 10 | + import path from 'node:path'; | ||
| 10 | 11 | import { type BenchmarkCliOptions, runI18nBenchmarks } from './benchmarks/i18n/index.mts'; | |
| 11 | 12 | ||
| 12 | 13 | function checkBuildStatus(logger: Console): boolean { | |
@@ -44,6 +45,8 @@ export default async function ( | |||
| 44 | 45 | concurrency?: string | number; | |
| 45 | 46 | build?: boolean; | |
| 46 | 47 | json?: boolean; | |
| 48 | + inProcess?: boolean; | ||
| 49 | + 'in-process'?: boolean; | ||
| 47 | 50 | saveBaseline?: string; | |
| 48 | 51 | 'save-baseline'?: string; | |
| 49 | 52 | compareBaseline?: string; | |
@@ -72,6 +75,7 @@ Options: | |||
| 72 | 75 | --iterations=<n> Number of measured iterations (default: 5) | |
| 73 | 76 | --warmup=<n> Number of warmup iterations (default: 2) | |
| 74 | 77 | --concurrency=<n> Override worker thread pool concurrency | |
| 78 | + --in-process Run all scenarios in a single process (useful for debugging) | ||
| 75 | 79 | --build Automatically build packages before benchmarking | |
| 76 | 80 | --json Output results in machine-readable JSON | |
| 77 | 81 | --save-baseline=<file> Save run results to a baseline JSON file | |
@@ -99,14 +103,45 @@ Options: | |||
| 99 | 103 | return 1; | |
| 100 | 104 | } | |
| 101 | 105 | ||
| 106 | + const rawSaveBaseline = options.saveBaseline ?? options['save-baseline']; | ||
| 107 | + const rawCompareBaseline = options.compareBaseline ?? options['compare-baseline']; | ||
| 108 | + | ||
| 109 | + const iterations = options.iterations !== undefined ? Number(options.iterations) : undefined; | ||
| 110 | + const warmup = options.warmup !== undefined ? Number(options.warmup) : undefined; | ||
| 111 | + const concurrency = options.concurrency !== undefined ? Number(options.concurrency) : undefined; | ||
| 112 | + | ||
| 113 | + if (iterations !== undefined && (!Number.isInteger(iterations) || iterations < 1)) { | ||
| 114 | + // eslint-disable-next-line no-console | ||
| 115 | + console.error('Error: --iterations must be a positive integer.'); | ||
| 116 | + | ||
| 117 | + return 1; | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + if (warmup !== undefined && (!Number.isInteger(warmup) || warmup < 0)) { | ||
| 121 | + // eslint-disable-next-line no-console | ||
| 122 | + console.error('Error: --warmup must be a non-negative integer.'); | ||
| 123 | + | ||
| 124 | + return 1; | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + if (concurrency !== undefined && (!Number.isInteger(concurrency) || concurrency < 1)) { | ||
| 128 | + // eslint-disable-next-line no-console | ||
| 129 | + console.error('Error: --concurrency must be a positive integer.'); | ||
| 130 | + | ||
| 131 | + return 1; | ||
| 132 | + } | ||
| 133 | + | ||
| 102 | 134 | const cliOptions: BenchmarkCliOptions = { | |
| 103 | 135 | scenario: options.scenario, | |
| 104 | - iterations: options.iterations !== undefined ? Number(options.iterations) : undefined, | ||
| 105 | - warmup: options.warmup !== undefined ? Number(options.warmup) : undefined, | ||
| 106 | - concurrency: options.concurrency !== undefined ? Number(options.concurrency) : undefined, | ||
| 136 | + iterations, | ||
| 137 | + warmup, | ||
| 138 | + concurrency, | ||
| 107 | 139 | json: Boolean(options.json), | |
| 108 | - saveBaseline: options.saveBaseline ?? options['save-baseline'], | ||
| 109 | - compareBaseline: options.compareBaseline ?? options['compare-baseline'], | ||
| 140 | + inProcess: Boolean(options.inProcess ?? options['in-process']), | ||
| 141 | + saveBaseline: rawSaveBaseline ? path.resolve(_cwd, String(rawSaveBaseline)) : undefined, | ||
| 142 | + compareBaseline: rawCompareBaseline | ||
| 143 | + ? path.resolve(_cwd, String(rawCompareBaseline)) | ||
| 144 | + : undefined, | ||
| 110 | 145 | }; | |
| 111 | 146 | ||
| 112 | 147 | const { exitCode } = await runI18nBenchmarks(cliOptions); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,8 +13,8 @@ import { createRequire } from 'node:module'; | |||
| 13 | 13 | ||
| 14 | 14 | import path from 'node:path'; | |
| 15 | 15 | ||
| 16 | - import type { BuildOutputFile } from '../../../dist/@angular/build/src/tools/esbuild/bundler-files.d.ts'; | ||
| 17 | - import type { LocaleInlineOptions } from '../../../dist/@angular/build/src/tools/esbuild/i18n-inliner.d.ts'; | ||
| 16 | + import type { BuildOutputFile } from '../../../packages/angular/build/src/tools/esbuild/bundler-files.js'; | ||
| 17 | + import type { LocaleInlineOptions } from '../../../packages/angular/build/src/tools/esbuild/i18n-inliner.js'; | ||
| 18 | 18 | ||
| 19 | 19 | // Setup module paths to resolve dependencies from packages/angular/build | |
| 20 | 20 | const requireFromBuild = createRequire( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -63,9 +63,9 @@ export async function runScenario( | |||
| 63 | 63 | const warmup = options.warmup ?? 2; | |
| 64 | 64 | const iterations = options.iterations ?? 5; | |
| 65 | 65 | ||
| 66 | - await scenario.setup?.(); | ||
| 67 | - | ||
| 68 | 66 | try { | |
| 67 | + await scenario.setup?.(); | ||
| 68 | + | ||
| 69 | 69 | // Warmup phase | |
| 70 | 70 | for (let w = 0; w < warmup; w++) { | |
| 71 | 71 | // Force GC if available between warmups | |
@@ -106,10 +106,10 @@ export async function runScenario( | |||
| 106 | 106 | if (rssDelta > maxRssDeltaBytes) { | |
| 107 | 107 | maxRssDeltaBytes = rssDelta; | |
| 108 | 108 | } | |
| 109 | - finalHeap = memAfter.heapUsed; | ||
| 110 | 109 | ||
| 111 | 110 | // Force GC immediately after iteration to clean main thread isolate | |
| 112 | 111 | global.gc?.(); | |
| 112 | + finalHeap = process.memoryUsage().heapUsed; | ||
| 113 | 113 | } | |
| 114 | 114 | ||
| 115 | 115 | // Sort ascending for percentile computation | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -82,9 +82,12 @@ export async function runI18nBenchmarks( | |||
| 82 | 82 | } | |
| 83 | 83 | ||
| 84 | 84 | const proc = spawnSync(process.execPath, args, { encoding: 'utf-8' }); | |
| 85 | - if (proc.status !== 0) { | ||
| 85 | + if (proc.status !== 0 || proc.error) { | ||
| 86 | 86 | // eslint-disable-next-line no-console | |
| 87 | - console.error(`Error running scenario ${scenario.name}:\n${proc.stderr || proc.stdout}`); | ||
| 87 | + console.error( | ||
| 88 | + `Error running scenario ${scenario.name}:\n` + | ||
| 89 | + (proc.error?.message ?? (proc.stderr || proc.stdout)), | ||
| 90 | + ); | ||
| 88 | 91 | ||
| 89 | 92 | return { results, exitCode: 1 }; | |
| 90 | 93 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,7 +17,9 @@ const buildNodeModules = path.resolve( | |||
| 17 | 17 | ||
| 18 | 18 | const currentPath = process.env.NODE_PATH ?? ''; | |
| 19 | 19 | if (!currentPath.includes(buildNodeModules)) { | |
| 20 | - process.env.NODE_PATH = currentPath ? `${buildNodeModules}:${currentPath}` : buildNodeModules; | ||
| 20 | + process.env.NODE_PATH = currentPath | ||
| 21 | + ? `${buildNodeModules}${path.delimiter}${currentPath}` | ||
| 22 | + : buildNodeModules; | ||
| 21 | 23 | // Initialize internal search paths for Node CommonJS loader | |
| 22 | 24 | // eslint-disable-next-line @typescript-eslint/no-explicit-any | |
| 23 | 25 | (Module as any)._initPaths?.(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,9 +13,10 @@ import fs from 'node:fs/promises'; | |||
| 13 | 13 | import { createRequire } from 'node:module'; | |
| 14 | 14 | import os from 'node:os'; | |
| 15 | 15 | import path from 'node:path'; | |
| 16 | + import { pathToFileURL } from 'node:url'; | ||
| 16 | 17 | ||
| 17 | - import type { BuildOutputFile } from '../../../dist/@angular/build/src/tools/esbuild/bundler-files.d.ts'; | ||
| 18 | - import type { LocaleInlineOptions } from '../../../dist/@angular/build/src/tools/esbuild/i18n-inliner.d.ts'; | ||
| 18 | + import type { BuildOutputFile } from '../../../packages/angular/build/src/tools/esbuild/bundler-files.js'; | ||
| 19 | + import type { LocaleInlineOptions } from '../../../packages/angular/build/src/tools/esbuild/i18n-inliner.js'; | ||
| 19 | 20 | import { generateSyntheticBundle, generateTranslations, initializeFixtures } from './fixtures.mts'; | |
| 20 | 21 | import type { BenchmarkScenario } from './harness.mts'; | |
| 21 | 22 | ||
@@ -25,7 +26,7 @@ const requireFromBuild = createRequire( | |||
| 25 | 26 | ||
| 26 | 27 | const { I18nInliner } = requireFromBuild( | |
| 27 | 28 | '../../../dist/@angular/build/src/tools/esbuild/i18n-inliner.js', | |
| 28 | - ) as typeof import('../../../dist/@angular/build/src/tools/esbuild/i18n-inliner.d.ts'); | ||
| 29 | + ) as typeof import('../../../packages/angular/build/src/tools/esbuild/i18n-inliner.js'); | ||
| 29 | 30 | ||
| 30 | 31 | export interface ScenarioFactoryOptions { | |
| 31 | 32 | concurrency?: number; | |
@@ -124,6 +125,15 @@ function calculateInputSizeBytes(files: BuildOutputFile[]): number { | |||
| 124 | 125 | }, 0); | |
| 125 | 126 | } | |
| 126 | 127 | ||
| 128 | + /** | ||
| 129 | + * Note on Worker Pool Lifecycle: | ||
| 130 | + * Each scenario's run() method instantiates and closes an I18nInliner per iteration. | ||
| 131 | + * This is designed as a macro benchmark to reflect the cold-start behavior of single-shot | ||
| 132 | + * CLI build invocations (including worker thread pool initialization, task dispatch, | ||
| 133 | + * inlining transformations, and thread pool shutdown). Warmup iterations warm up the | ||
| 134 | + * main-thread V8 isolate and runtime paths, while worker threads are initialized per iteration. | ||
| 135 | + */ | ||
| 136 | + | ||
| 127 | 137 | /** | |
| 128 | 138 | * 1. Standard App Scenario: | |
| 129 | 139 | * 1 main bundle (1 MB) + 20 route chunks (50 KB) = ~2 MB input JS, 8 locales, maps enabled. | |
@@ -350,15 +360,28 @@ export function createPersistentCacheWarmScenario( | |||
| 350 | 360 | ||
| 351 | 361 | // Prime the persistent cache out-of-process so cold worker thread allocations | |
| 352 | 362 | // do not inflate this process's RSS metrics. | |
| 363 | + const scenariosUrl = pathToFileURL(path.resolve(import.meta.dirname, './scenarios.mts')).href; | ||
| 353 | 364 | const primerCode = | |
| 354 | - `import { primeCache } from ${JSON.stringify(path.resolve(import.meta.dirname, './scenarios.mts'))};\n` + | ||
| 365 | + `import { primeCache } from ${JSON.stringify(scenariosUrl)};\n` + | ||
| 355 | 366 | `await primeCache(${JSON.stringify(cacheDir)}, ${options.concurrency ?? 'undefined'});\n`; | |
| 356 | 367 | ||
| 357 | - spawnSync( | ||
| 368 | + const primerProc = spawnSync( | ||
| 358 | 369 | process.execPath, | |
| 359 | - ['--no-warnings=ExperimentalWarning', '--experimental-transform-types', '-e', primerCode], | ||
| 370 | + [ | ||
| 371 | + '--no-warnings=ExperimentalWarning', | ||
| 372 | + '--experimental-transform-types', | ||
| 373 | + '--input-type=module', | ||
| 374 | + '-e', | ||
| 375 | + primerCode, | ||
| 376 | + ], | ||
| 360 | 377 | { stdio: 'inherit' }, | |
| 361 | 378 | ); | |
| 379 | + | ||
| 380 | + if (primerProc.status !== 0 || primerProc.error) { | ||
| 381 | + throw new Error( | ||
| 382 | + `Failed to prime cache for persistent-cache-warm scenario: ${primerProc.error?.message ?? primerProc.status}`, | ||
| 383 | + ); | ||
| 384 | + } | ||
| 362 | 385 | }, | |
| 363 | 386 | ||
| 364 | 387 | async run() { | |
@@ -384,11 +407,60 @@ export function createPersistentCacheWarmScenario( | |||
| 384 | 407 | }; | |
| 385 | 408 | } | |
| 386 | 409 | ||
| 410 | + /** | ||
| 411 | + * 6. Large Enterprise (10k translations) Scenario: | ||
| 412 | + * 1 main bundle (3 MB) + 100 chunks (50 KB), 32 locales, 10,000 translations, sourcemaps ON. | ||
| 413 | + * Maximum scale stress test for binary translation tables, memory retention, and multi-locale windows. | ||
| 414 | + */ | ||
| 415 | + export function createLargeEnterpriseScenario( | ||
| 416 | + options: ScenarioFactoryOptions = {}, | ||
| 417 | + ): BenchmarkScenario { | ||
| 418 | + let workload: GeneratedWorkload | undefined; | ||
| 419 | + | ||
| 420 | + return { | ||
| 421 | + name: 'large-enterprise-10k', | ||
| 422 | + description: | ||
| 423 | + 'Large Enterprise (10k msgs): 1 main (3 MB) + 100 chunks (50 KB), 32 locales, 10,000 translations', | ||
| 424 | + get inputSizeBytes() { | ||
| 425 | + return workload?.totalInputSizeBytes ?? 0; | ||
| 426 | + }, | ||
| 427 | + get localeCount() { | ||
| 428 | + return DEFAULT_LOCALES_32.length; | ||
| 429 | + }, | ||
| 430 | + async setup() { | ||
| 431 | + await initializeFixtures(); | ||
| 432 | + const files = createBundleSet(3 * 1024 * 1024, 100, 50 * 1024, 10000, true); | ||
| 433 | + const locales = generateTranslations(DEFAULT_LOCALES_32, 10000); | ||
| 434 | + | ||
| 435 | + workload = { | ||
| 436 | + files, | ||
| 437 | + locales, | ||
| 438 | + totalInputSizeBytes: calculateInputSizeBytes(files), | ||
| 439 | + }; | ||
| 440 | + }, | ||
| 441 | + async run() { | ||
| 442 | + if (!workload) { | ||
| 443 | + return; | ||
| 444 | + } | ||
| 445 | + const inliner = new I18nInliner({ | ||
| 446 | + missingTranslation: 'warning', | ||
| 447 | + maxConcurrency: options.concurrency, | ||
| 448 | + }); | ||
| 449 | + try { | ||
| 450 | + await inliner.inlineAll(workload.files, workload.locales); | ||
| 451 | + } finally { | ||
| 452 | + await inliner.close(); | ||
| 453 | + } | ||
| 454 | + }, | ||
| 455 | + }; | ||
| 456 | + } | ||
| 457 | + | ||
| 387 | 458 | export function getAllScenarios(options: ScenarioFactoryOptions = {}): BenchmarkScenario[] { | |
| 388 | 459 | return [ | |
| 389 | 460 | createStandardAppScenario(options), | |
| 390 | 461 | createStandardAppNoMapsScenario(options), | |
| 391 | 462 | createEnterpriseScenario(options), | |
| 463 | + createLargeEnterpriseScenario(options), | ||
| 392 | 464 | createMonolithicScenario(options), | |
| 393 | 465 | createPersistentCacheWarmScenario(options), | |
| 394 | 466 | ]; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments