-
Notifications
You must be signed in to change notification settings - Fork 4
CHANGE @W-20773111@ - One-off performance probe for the ESLint engine. #399
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
Open
aruntyagiTutu
wants to merge
6
commits into
dev
Choose a base branch
from
arun.tyagi/eslint_perf_test_via_unit
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a2a7506
One-off performance probe for the ESLint engine.
aruntyagiTutu 3bd5467
Merge branch 'dev' into arun.tyagi/eslint_perf_test_via_unit
aruntyagiTutu 5ae8756
compute peak_rss_mb uses max of sampler
aruntyagiTutu cbbc0cc
CHANGE @W-20773111@ - Perf test for run rules (#400)
aruntyagiTutu 6156068
CHANGE @W-20773111@ - Coverage utils: makeUnique deduplication and ma…
aruntyagiTutu 53561cd
CHANGE @W-20773111@ - test coverage file system and temp folder utili…
aruntyagiTutu 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
92 changes: 92 additions & 0 deletions
92
packages/code-analyzer-eslint-engine/test/perf-eslint-run.test.ts
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,92 @@ | ||
| import {Engine, RuleDescription, Workspace} from "@salesforce/code-analyzer-engine-api"; | ||
| import {ESLintEnginePlugin} from "../src"; | ||
| import {DEFAULT_CONFIG, ESLintEngineConfig} from "../src/config"; | ||
| import {createDescribeOptions, createRunOptions} from "./test-helpers"; | ||
|
|
||
| /** | ||
| * One-off performance probe for running ESLint rules (runRules). | ||
| * | ||
| * What this test does: | ||
| * - Instantiates the ESLint engine with the current base configuration. | ||
| * - Discovers rules (describeRules), then selects a subset to run (e.g., Recommended). | ||
| * - Runs the engine against the provided workspace (PERF_WS must be set). | ||
| * - Samples Node's resident set size (RSS) and prints a JSON summary: | ||
| * { | ||
| * "files_scanned": <unique files that produced violations>, | ||
| * "rules_run": <number of rules executed>, | ||
| * "run_ms": <wall time in milliseconds for runRules>, | ||
| * "peak_rss_mb": <approximate peak memory (MB) observed during the run>, | ||
| * "violations": <total violations found> | ||
| * } | ||
| * | ||
| * How to run (skipped by default; opt-in with env var): | ||
| * ESLINT_ENGINE_PERF_RUN=true PERF_WS="/absolute/path/to/project" PERF_DISCOVER=true \ | ||
| * npm run test-typescript -- packages/code-analyzer-eslint-engine/test/perf-eslint-run.test.ts | ||
| * | ||
| * Optional env vars: | ||
| * - PERF_RULES_LIMIT=200 → cap the number of rules to run (keeps runtime stable) | ||
| * - PERF_DISCOVER=true → let ESLint auto-discover configs from PERF_WS (sets config_root to PERF_WS) | ||
| * - You can toggle: | ||
| * // disable_react_base_config: true, | ||
| * // disable_typescript_base_config: true, | ||
| * in the config below to attribute parser/plugin costs. | ||
| */ | ||
| const RUN = process.env.ESLINT_ENGINE_PERF_RUN === 'true'; | ||
| (RUN ? describe : describe.skip)('ESLint engine perf (runRules one-off)', () => { | ||
| it('measures runRules wall time and peak RSS', async () => { | ||
| const cfg: ESLintEngineConfig = { | ||
| ...DEFAULT_CONFIG, | ||
| // Toggle to isolate costs if desired: | ||
| disable_react_base_config: false, | ||
| disable_typescript_base_config: true, | ||
| config_root: __dirname, | ||
| auto_discover_eslint_config: process.env.PERF_DISCOVER === 'true', | ||
| }; | ||
|
|
||
| const wsPath = process.env.PERF_WS; | ||
| if (!wsPath) { | ||
| throw new Error('PERF_WS env var must be set to an absolute path for runRules perf test.'); | ||
| } | ||
| const ws: Workspace = new Workspace('perf', [wsPath]); | ||
| if (process.env.PERF_DISCOVER === 'true') { | ||
| cfg.config_root = wsPath; | ||
| } | ||
|
|
||
| const engine: Engine = await new ESLintEnginePlugin().createEngine('eslint', cfg); | ||
|
|
||
| // Discover and select rules to run (Recommended by default), with an optional cap. | ||
| const discovered: RuleDescription[] = await engine.describeRules(createDescribeOptions(ws)); | ||
| const rulesToRun: string[] = discovered | ||
| .filter(r => r.tags.includes('Recommended')) | ||
| .slice(0, Number(process.env.PERF_RULES_LIMIT) || 200) | ||
| .map(r => r.name); | ||
|
|
||
| const peak = {rss: 0}; | ||
| const sampler = setInterval(() => { | ||
| const m = process.memoryUsage(); | ||
| if (m.rss > peak.rss) peak.rss = m.rss; | ||
| }, 50); | ||
|
|
||
| const mem0 = process.memoryUsage().rss; | ||
| const t0 = performance.now(); | ||
| const results = await engine.runRules(rulesToRun, createRunOptions(ws)); | ||
| const t1 = performance.now(); | ||
| const mem1 = process.memoryUsage().rss; | ||
| clearInterval(sampler); | ||
|
|
||
| // Calculate files that produced violations (as a proxy for scanned footprint). | ||
| const filesScanned = Array.from(new Set(results.violations.map(v => v.codeLocations[0].file))).length; | ||
|
|
||
| // eslint-disable-next-line no-console | ||
| console.log(JSON.stringify({ | ||
| files_scanned: filesScanned, | ||
| rules_run: rulesToRun.length, | ||
| run_ms: Math.round(t1 - t0), | ||
| peak_rss_mb: Math.round(Math.max(peak.rss, mem0, mem1) / (1024 * 1024)), | ||
| violations: results.violations.length | ||
| }, null, 2)); | ||
|
|
||
| expect(rulesToRun.length).toBeGreaterThan(0); | ||
| }); | ||
| }); | ||
|
|
||
90 changes: 90 additions & 0 deletions
90
packages/code-analyzer-eslint-engine/test/perf-eslint.test.ts
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,90 @@ | ||
| import {Engine, RuleDescription, Workspace} from "@salesforce/code-analyzer-engine-api"; | ||
| import {ESLintEnginePlugin} from "../src"; | ||
| import {DEFAULT_CONFIG, ESLintEngineConfig} from "../src/config"; | ||
| import {createDescribeOptions} from "./test-helpers"; | ||
| import * as path from "node:path"; | ||
|
|
||
| /** | ||
| * One-off performance probe for the ESLint engine. | ||
| * | ||
| * What this test does: | ||
| * - Instantiates the ESLint engine with the current base configuration. | ||
| * - Calls engine.describeRules(), which exercises rule discovery (parsing configs, resolving plugins, building rule lists). | ||
| * - Samples Node's resident set size (RSS) periodically to estimate the peak memory use during describeRules(). | ||
| * - Emits a single JSON object to stdout with: | ||
| * { | ||
| * "rule_count": <number of rules discovered>, | ||
| * "describe_ms": <wall time in milliseconds for describeRules>, | ||
| * "peak_rss_mb": <approximate peak memory (MB) observed during the call> | ||
| * } | ||
| * | ||
| * How to run (skipped by default; opt-in with env var): | ||
| * ESLINT_ENGINE_PERF=true npm run test-typescript -- packages/code-analyzer-eslint-engine/test/perf-eslint.test.ts | ||
| * | ||
| * ESLINT_ENGINE_PERF=true PERF_WS="/Users/arun.tyagi/projects/dreamhouse-sfdx" PERF_DISCOVER=true \ | ||
| * npm run test-typescript -- packages/code-analyzer-eslint-engine/test/perf-eslint.test.ts | ||
| * | ||
| * What to look for: | ||
| * - describe_ms: Use this to compare wall-time across changes. Lower is better. | ||
| * - peak_rss_mb: Track memory impact/regressions (e.g., when enabling additional parsers/plugins). | ||
| * - rule_count: Sanity check that you are comparing like-for-like runs (similar rule surface). | ||
| * | ||
| * How to isolate parser/plugin costs: | ||
| * - Set disable_react_base_config: true → measure baseline without React rules/plugins. | ||
| * - Set disable_typescript_base_config: true → measure without the TypeScript parser/rules. | ||
| * Run the test multiple times, toggling these flags, and compare the outputs. | ||
| * | ||
| * Notes: | ||
| * - This is a coarse probe (RSS sampling every 50ms). For deeper analysis, also try: | ||
| * node --cpu-prof --heap-prof ./node_modules/.bin/jest packages/code-analyzer-eslint-engine/test/perf-eslint.test.ts | ||
| * and inspect the generated profiles in Chrome DevTools. | ||
| */ | ||
| const RUN = process.env.ESLINT_ENGINE_PERF === 'true'; | ||
| (RUN ? describe : describe.skip)('ESLint engine perf (one-off)', () => { | ||
| it('measures describeRules wall time and peak RSS', async () => { | ||
| const config: ESLintEngineConfig = { | ||
| ...DEFAULT_CONFIG, | ||
| // Toggle these to isolate costs: | ||
| // disable_react_base_config: true, | ||
| // disable_typescript_base_config: true, | ||
| config_root: __dirname | ||
| }; | ||
|
|
||
| // If a workspace path is provided (PERF_WS), analyze that project. | ||
| // Optionally allow ESLint to auto-discover configs from that project (PERF_DISCOVER=true). | ||
| const wsPath = process.env.PERF_WS; | ||
| const ws: Workspace | undefined = wsPath ? new Workspace('perf', [wsPath]) : undefined; | ||
| if (wsPath && process.env.PERF_DISCOVER === 'true') { | ||
| (config as ESLintEngineConfig).auto_discover_eslint_config = true; | ||
| (config as ESLintEngineConfig).config_root = wsPath; | ||
| } | ||
|
|
||
| // Create engine with the chosen config flags | ||
| const engine: Engine = await new ESLintEnginePlugin().createEngine('eslint', config); | ||
|
|
||
| // Track peak RSS during the measured operation with a light-weight sampler. | ||
| const peak = { rss: 0 }; | ||
| const sampler = setInterval(() => { | ||
| const m = process.memoryUsage(); | ||
| if (m.rss > peak.rss) peak.rss = m.rss; | ||
| }, 50); | ||
|
|
||
| // Measure wall time of describeRules (rule discovery). | ||
| const mem0 = process.memoryUsage().rss; | ||
| const t0 = performance.now(); | ||
| const rules: RuleDescription[] = await engine.describeRules(createDescribeOptions(ws)); | ||
| const t1 = performance.now(); | ||
| const mem1 = process.memoryUsage().rss; | ||
| clearInterval(sampler); | ||
|
|
||
| // eslint-disable-next-line no-console | ||
| console.log(JSON.stringify({ | ||
| rule_count: rules.length, | ||
| describe_ms: Math.round(t1 - t0), | ||
| peak_rss_mb: Math.round(Math.max(peak.rss, mem0, mem1) / (1024 * 1024)) | ||
| }, null, 2)); | ||
|
|
||
| expect(rules.length).toBeGreaterThan(0); | ||
| }); | ||
| }); | ||
|
|
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
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.
Will this be also visible to our users?