Repository navigation
perf: batch the blame, index the deps manifests, and add --out #47
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
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
52effae
docs(deps): go.sum records version-hash pairs, not "no versions"
modusensus 110e5f0
feat(cli): --out <file> writes the run's artifact instead of stdout
modusensus 22491ed
fix(history): the porcelain blame parser accepts sha256 object ids
modusensus 870eaa1
perf(history): blame deleted ranges in batches, one process per ~400 …
modusensus e4788e4
bench(deps): scaling baseline for the whole-manifest (--all) path
modusensus effc430
perf(deps): build the name index and line table once per manifest
modusensus ec10bac
docs(agents): record --out, the blame batching, the deps index, and t…
modusensus e46b56c
docs(ci): the artifact recipe is blocking — drop continue-on-error fr…
modusensus ebc3ff1
docs(perf): attribute the measured tier to the invocation that produc…
modusensus 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,128 @@ | ||
| 'use strict'; | ||
|
|
||
| /** | ||
| * Scaling benchmark for the `deps` producer's whole-manifest path. | ||
| * | ||
| * `euthyna audit` queries EVERY dependency the manifest names (the `--all` | ||
| * shape). The per-dep resolvers re-scan the manifest text for each dependency — | ||
| * `resolveNpm` iterates every `packages` key per dep, `resolveCargo` splits the | ||
| * whole file per dep, and each evidence line lookup walks the text prefix — so | ||
| * the whole-manifest cost may grow faster than the manifest itself. This script | ||
| * measures exactly that shape at increasing sizes, so a change to indexing has | ||
| * a baseline to be judged against, and a reader can see at a glance whether the | ||
| * per-dependency cost is flat or compounding. | ||
| * | ||
| * The manifests are synthetic but shape-real: npm v3 with scoped and unscoped | ||
| * names, Cargo.lock with [[package]] blocks. Absolute numbers are | ||
| * machine-dependent; the per-dependency ratio is the number that matters. | ||
| * | ||
| * node bench/perf-deps.js [--npm-sizes 500,1000,2000,4000] [--cargo-sizes 500,1000,2000] | ||
| * | ||
| * 索引化之前实测(本机):npm 每依赖 0.46 → 0.92 → 1.81 → 3.75 ms(清单每翻倍 | ||
| * 翻一倍,O(n²) 形状),cargo 0.27 → 0.91 ms/依赖 同形。 | ||
| * 索引化之后实测(同机):npm 0.04 → 0.09 ms/依赖,cargo 恒定 ~0.05 —— 4000 依赖 | ||
| * 从 15.0s 降到 0.36s。npm 残留的轻微超线性来自每个命中一次的原生 indexOf 证据 | ||
| * 锚定(O(文件) 但字节速度),绝对值已不构成实际天花板。 | ||
| */ | ||
|
|
||
| const fs = require('node:fs'); | ||
| const os = require('node:os'); | ||
| const path = require('node:path'); | ||
|
|
||
| const args = process.argv.slice(2); | ||
| const opt = (name, fallback) => { | ||
| const i = args.indexOf(name); | ||
| return i === -1 ? fallback : args[i + 1]; | ||
| }; | ||
| const parseSizes = (raw) => | ||
| String(raw) | ||
| .split(',') | ||
| .map(Number); | ||
| const NPM_SIZES = parseSizes(opt('--npm-sizes', '500,1000,2000,4000')); | ||
| const CARGO_SIZES = parseSizes(opt('--cargo-sizes', '500,1000,2000')); | ||
|
|
||
| function npmLockfile(n) { | ||
| const packages = { | ||
| '': { name: 'fixture', version: '1.0.0', dependencies: {} } | ||
| }; | ||
| for (let i = 0; i < n; i++) { | ||
| // Scoped names every seventh package: resolveNpm must handle both, and the | ||
| // nested-scope key form is what makes its split-by-node_modules non-trivial. | ||
| const name = i % 7 === 0 ? `@scope/pkg-${i}` : `pkg-${i}`; | ||
| packages[`node_modules/${name}`] = { | ||
| version: `${(i % 20) + 1}.${i % 9}.${i % 5}`, | ||
| resolved: `https://registry.example/${name}/-/${name}.tgz`, | ||
| integrity: `sha512-${'a'.repeat(40)}` | ||
| }; | ||
| } | ||
| return JSON.stringify({ name: 'fixture', lockfileVersion: 3, packages }, null, 2); | ||
| } | ||
|
|
||
| function cargoLockfile(n) { | ||
| let text = '# This file is automatically @generated by Cargo.\nversion = 3\n\n'; | ||
| for (let i = 0; i < n; i++) { | ||
| text += `[[package]]\nname = "crate-${i}"\nversion = "1.${i % 10}.${i % 7}"\nsource = "registry+https://github.com/rust-lang/crates.io-index"\nchecksum = "${'b'.repeat(40)}"\n\n`; | ||
| } | ||
| return text; | ||
| } | ||
|
|
||
| async function measure(label, file, type, text, size) { | ||
| const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'euthyna-deps-perf-')); | ||
| fs.writeFileSync(path.join(dir, file), text); | ||
| try { | ||
| const { listDependencies, collectDependencyFacts } = await import('../src/facts/deps.js'); | ||
| const names = listDependencies(type, text); | ||
| const start = process.hrtime.bigint(); | ||
| const { measured } = await collectDependencyFacts({ cwd: dir, deps: names }); | ||
| const ms = Number(process.hrtime.bigint() - start) / 1e6; | ||
| if (!measured) throw new Error(`${label} ${size}: the producer could not measure its own fixture`); | ||
| process.stdout.write( | ||
| ` ${String(size).padStart(6)} 依赖 ${ms.toFixed(0).padStart(7)} ms (${(ms / size).toFixed(2)} ms/依赖, 清单 ${(text.length / 1024 / 1024).toFixed(1)} MB)\n` | ||
| ); | ||
| return ms / size; | ||
| } finally { | ||
| fs.rmSync(dir, { recursive: true, force: true }); | ||
| } | ||
| } | ||
|
|
||
| async function main() { | ||
| if (!NPM_SIZES.every(Number.isFinite) || !CARGO_SIZES.every(Number.isFinite)) { | ||
| throw new Error('--npm-sizes/--cargo-sizes 必须是逗号分隔的整数'); | ||
| } | ||
|
|
||
| const results = []; | ||
| for (const size of NPM_SIZES) { | ||
| const ratio = await measure('npm', 'package-lock.json', 'npm', npmLockfile(size), size); | ||
| results.push({ kind: 'npm', size, ratio }); | ||
| } | ||
| for (const size of CARGO_SIZES) { | ||
| const ratio = await measure('cargo', 'Cargo.lock', 'cargo', cargoLockfile(size), size); | ||
| results.push({ kind: 'cargo', size, ratio }); | ||
| } | ||
|
|
||
| for (const kind of ['npm', 'cargo']) { | ||
| const rows = results.filter((r) => r.kind === kind); | ||
| if (rows.length < 2) continue; | ||
| const spread = Math.max(...rows.map((r) => r.ratio)) / Math.min(...rows.map((r) => r.ratio)); | ||
| const first = rows[0]; | ||
| const last = rows[rows.length - 1]; | ||
| console.log(`\n结论 (${kind}):`); | ||
| if (last.ratio > first.ratio * 2) { | ||
| console.log( | ||
| ' 每依赖成本在随清单变大 —— 超线性。若绝对值回到秒级,' + | ||
| '先查每依赖是否又在重扫全文(name→条目索引是否还在),' + | ||
| '以及证据行锚定的 indexOf 是否回到了逐字符的前缀遍历。' | ||
| ); | ||
| } else if (last.ratio < first.ratio * 0.5) { | ||
| console.log(' 每依赖成本在变小 —— 次线性,固定开销在小规模档位里占比较高。'); | ||
| } else { | ||
| console.log(' 每依赖成本基本恒定 —— 线性缩放,当前形状没有明显天花板。'); | ||
| } | ||
| } | ||
| console.log(' 绝对数值依赖机器;横向比较 ms/依赖 而非 ms。'); | ||
| } | ||
|
|
||
| main().catch((error) => { | ||
| console.error(`bench/perf-deps.js: ${error.message}`); | ||
| process.exitCode = 1; | ||
| }); |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: slow-stack/euthyna
Length of output: 6042
Remove
continue-on-errorfrom the artifact recipe.As written, the recipe makes the audit step non-blocking. A job that copies it can pass when the audit exits
1,2, or10. Theif: always()upload step still runs after a failed audit, so the report is still attached. The section also states that the step's status is the audit's own, which thecontinue-on-errorline contradicts.This matches the document's default. The one-step form blocks on exit
10. The two-step form is the only documented non-blocking pattern.Apply the same change to
docs/ci-integration-zh.md. The-zhfile is the original, and the English file is its translation.Suggested fix
- name: Change-surface audit run: npx --yes euthyna@latest audit --base "origin/${{ github.base_ref }}" --head HEAD --out audit-report.txt - continue-on-error: true id: audit