-
Notifications
You must be signed in to change notification settings - Fork 14
Increase benchmark sampling 5x for CI stability #187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
NullVoxPopuli
merged 10 commits into
ember-tooling:main
from
NullVoxPopuli-ai-agent:increase-benchmark-sampling
Mar 20, 2026
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7db6dcd
Increase benchmark sampling 5x for more stable CI results
NullVoxPopuli 18d2ead
Use mitata gc('inner') and p50 for stable CI benchmarks
NullVoxPopuli e208798
Replace loader hook with iteration loops for CI stability
NullVoxPopuli 87c663c
Increase iteration counts for small/medium benchmarks
NullVoxPopuli c864d12
Add CPU pinning and priority for local benchmarks
NullVoxPopuli 75fea38
Use do_not_optimize to prevent V8 DCE on parse results
NullVoxPopuli ba324f7
Use sudo nice for high priority without requiring root shell
NullVoxPopuli 23fa308
DRY up bench scripts, remove sudo logic, add reliability tips
NullVoxPopuli 6271cdf
Apply suggestion from @NullVoxPopuli
NullVoxPopuli 00417d1
Fix camelCase lint error for do_not_optimize import
NullVoxPopuli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /** | ||
| * Shared utilities for benchmark formatting scripts. | ||
| */ | ||
|
|
||
| import { readFileSync } from 'node:fs'; | ||
|
|
||
| export function formatTime(ns) { | ||
| if (ns >= 1e6) return `${(ns / 1e6).toFixed(2)} ms`; | ||
| if (ns >= 1e3) return `${(ns / 1e3).toFixed(2)} µs`; | ||
| return `${ns.toFixed(2)} ns`; | ||
| } | ||
|
|
||
| export function deltaEmoji(pct) { | ||
| const abs = Math.abs(pct); | ||
| if (abs < 2) return '⚪'; | ||
| if (pct <= -5) return '🟢'; | ||
| if (pct >= 5) return '🔴'; | ||
| if (pct < 0) return '🟢'; | ||
| return '🟠'; | ||
| } | ||
|
|
||
| /** | ||
| * Parse benchmark JSON results into control/experiment pairs with deltas. | ||
| * Uses p50 (median) which is more robust to outliers than avg. | ||
| */ | ||
| export function parsePairs(json) { | ||
| const pairs = new Map(); | ||
|
|
||
| for (const trial of json.benchmarks || []) { | ||
| for (const r of trial.runs || []) { | ||
| if (!r.stats) continue; | ||
| const m = r.name.match(/^(.+)\s+\((control|experiment)\)$/); | ||
| if (!m) continue; | ||
| const [, key, role] = m; | ||
| if (!pairs.has(key)) pairs.set(key, {}); | ||
| pairs.get(key)[role] = r.stats; | ||
| } | ||
| } | ||
|
|
||
| const rows = []; | ||
| for (const [name, { control, experiment }] of pairs) { | ||
| if (!control || !experiment) continue; | ||
| const ctrlVal = control.p50 ?? control.avg; | ||
| const expVal = experiment.p50 ?? experiment.avg; | ||
| const delta = ((expVal - ctrlVal) / ctrlVal) * 100; | ||
| rows.push({ name, control: ctrlVal, experiment: expVal, delta }); | ||
| } | ||
|
|
||
| return rows; | ||
| } | ||
|
|
||
| /** | ||
| * Read and parse the benchmark JSON results file. | ||
| */ | ||
| export function readBenchJSON(path) { | ||
| return JSON.parse(readFileSync(path, 'utf8')); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,39 +1,48 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # Check CPU tuning on Linux — poor settings cause massive variance | ||
| hw_warnings="" | ||
| export BENCH_JSON_OUTPUT=./bench-results.json | ||
|
|
||
| pnpm bench:compare | ||
|
|
||
| echo "" | ||
| echo "━━━ Summary ━━━" | ||
| node scripts/format-bench-cli.mjs | ||
|
|
||
| # Print tips for reducing variance | ||
| echo "━━━ Tips for more reliable results ━━━" | ||
| echo "" | ||
|
|
||
| tips=() | ||
|
|
||
| if [ -f /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor ]; then | ||
| gov=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor) | ||
| if [ "$gov" != "performance" ]; then | ||
| hw_warnings+="⚠️ CPU governor is '$gov' — benchmark results will be noisy. | ||
| Fix with: sudo cpupower frequency-set -g performance | ||
| " | ||
| tips+=("CPU governor is '$gov' — set to 'performance' for fixed frequency:") | ||
| tips+=(" sudo cpupower frequency-set -g performance") | ||
| tips+=("") | ||
| fi | ||
| fi | ||
|
|
||
| if [ -f /sys/devices/system/cpu/cpufreq/boost ]; then | ||
| boost=$(cat /sys/devices/system/cpu/cpufreq/boost) | ||
| if [ "$boost" = "1" ]; then | ||
| hw_warnings+="⚠️ CPU boost is enabled — frequency varies with thermals. | ||
| Fix with: echo 0 | sudo tee /sys/devices/system/cpu/cpufreq/boost | ||
| " | ||
| tips+=("CPU boost is enabled — disable to prevent thermal-dependent frequency:") | ||
| tips+=(" echo 0 | sudo tee /sys/devices/system/cpu/cpufreq/boost") | ||
| tips+=("") | ||
| fi | ||
| elif [ -f /sys/devices/system/cpu/intel_pstate/no_turbo ]; then | ||
| no_turbo=$(cat /sys/devices/system/cpu/intel_pstate/no_turbo) | ||
| if [ "$no_turbo" = "0" ]; then | ||
| tips+=("Intel Turbo Boost is enabled — disable to prevent thermal-dependent frequency:") | ||
| tips+=(" echo 1 | sudo tee /sys/devices/system/cpu/intel_pstate/no_turbo") | ||
| tips+=("") | ||
| fi | ||
| fi | ||
|
|
||
| if [ -n "$hw_warnings" ]; then | ||
| echo "" | ||
| echo "$hw_warnings" | ||
| fi | ||
|
|
||
| export BENCH_JSON_OUTPUT=./bench-results.json | ||
|
|
||
| pnpm bench:compare | ||
| tips+=("Close other applications to reduce CPU contention") | ||
| tips+=("Run multiple times — if deltas flip sign between runs, they're noise") | ||
|
|
||
| for tip in "${tips[@]}"; do | ||
| echo " $tip" | ||
| done | ||
| echo "" | ||
| echo "━━━ Summary ━━━" | ||
| node scripts/format-bench-cli.mjs | ||
|
|
||
| if [ -n "$hw_warnings" ]; then | ||
| echo "$hw_warnings" | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| #!/usr/bin/env bash | ||
| # | ||
| # Wrapper that runs a node command with CPU pinning when available. | ||
| # | ||
| # Usage: ./scripts/run-bench.sh <node args...> | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| CMD=(node --expose-gc "$@") | ||
|
|
||
| # CPU pinning on Linux — keep the process on a single core | ||
| if command -v taskset &>/dev/null; then | ||
| CMD=(taskset -c 0 "${CMD[@]}") | ||
| echo "📌 CPU pinning enabled (taskset -c 0)" >&2 | ||
| echo "" >&2 | ||
| fi | ||
|
|
||
| exec "${CMD[@]}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.