sfcc-perf
v0.1.1
Published
Statically traces Salesforce B2C Commerce (SFCC) endpoints through your cartridge path - SFRA routes, SCAPI Custom APIs, hooks, job steps - and produces a latency model and Markdown report compatible with the SFCC Performance Analyzer web tool.
Maintainers
Readme
sfcc-perf
SFCC Performance Analyser - statically traces Salesforce B2C Commerce (SFCC) endpoints through your own cartridge code, builds a latency model with the same engine as the SFCC Performance Analyzer web tool, writes a Markdown report, and opens it in that same analyzer on your machine - waterfall, flow, outline, findings, what-if edits - with nothing uploaded.
It's static analysis: nothing runs on a sandbox, no credentials needed. Point it at the repository that contains your cartridges.
npx sfcc-perf init # paste your cartridge path from Business Manager
npx sfcc-perf --list
npx sfcc-perf Product-Show --out reports/Product-Show.md
npx sfcc-perf show reports/Product-Show.md # open it in the analyzer, locallyThose commands work straight away with npx. To pin a version for your team and CI, add it to the repository:
npm install --save-dev sfcc-perfFormerly published as
sfcc-performance-analyser. Replace that dependency withsfcc-perf; the command (sfcc-perf), config file and report format are unchanged, and older reports still import into the web tool.
Cartridge path (required)
The cartridge path decides which cartridge overrides which, so it is required and never guessed - a repo can contain dozens of cartridges, and several sites. Use the exact colon-separated list from Business Manager › Administration › Sites › Manage Sites › <site> › Settings › Cartridges:
- Interactively: the first time you run it in a terminal without one, you're asked for it (a
site.xmlvalue in the repo is offered as the default) and can save it to.sfcc-perf.json.sfcc-perf initasks again any time. - In CI / scripts: commit the
.sfcc-perf.jsonthatinitwrites, or pass--cartridge-path "app_custom:int_payment:app_storefront_base". Without either, the command exits 1 with instructions - it never stops to ask when there's no terminal, in CI, with--jsonor--no-prompt.
Cartridges on the path that aren't in the repo are skipped with a note; cartridge folders that aren't on the path are ignored.
Where it runs from: the nearest folder (the current one or above) with a .sfcc-perf.json is the project root, so running it inside a cartridge folder still uses the saved path. Without a config file it scans the current folder, or --root <folder>. A folder with no cartridges (folders containing a cartridge/ directory) stops with that message instead of asking for a path. If .sfcc-perf.json can't be written (read-only checkout), the path you typed is used for that run only.
A controller using module.superModule needs the cartridge below it on the path (usually app_storefront_base). If that cartridge is missing, the report is marked as an incomplete trace, not passed off as a smaller model.
What it traces
| Entry | Example id |
|---|---|
| SFRA controller route | Product-Show |
| SCAPI Custom API endpoint | api:loyalty/getPoints |
| OCAPI / SCAPI / custom hook | hook:dw.ocapi.shop.basket.beforePATCH |
| Job step (steptypes.json) | job:custom.ExportOrders |
| Any function | cartridges/app_x/cartridge/scripts/foo.js#bar |
It resolves the cartridge path, SFRA extend/append/prepend/replace chains, */cartridge/… and module.superModule requires, helpers, models, hooks.json hooks, Service Framework calls (with timeouts from services.xml), Transaction.wrap, CacheMgr caches, the page cache, ISML remote includes / slots / content assets, branches and loops. Each SFCC API call becomes one of the web tool's operation blocks.
CLI
sfcc-perf --list # every traceable entry point
sfcc-perf Product-Show # Markdown report to stdout
sfcc-perf Product-Show --out perf/Product-Show.md # … to a file
sfcc-perf Product-Show Cart-AddProduct --out-dir perf
sfcc-perf --all --json # every entry, JSON summary, reports in .sfcc-perf/reports
sfcc-perf --all --max-p95 900 # exit 2 if any modeled P95 score > 900 ms
sfcc-perf --all --strict # exit 3 if any trace is incompleteRun sfcc-perf --help for all options.
Open a report locally
Every run that writes a report ends with the command to open it:
✓ Product-Show: avg 507.1 ms · p95 1018.1 ms · 18 ops → reports/Product-Show.md
Open it in the analyzer (locally, offline):
npx sfcc-perf show reports/Product-Show.mdsfcc-perf show <report.md> writes reports/Product-Show.html next to the report and opens it in your browser. It's the web analyzer itself (the same UI, bundled into the package), with the report already loaded: Waterfall, Flow and Analysis views, every operation in the Outline, findings, and a report → now comparison while you change latencies, cache rates or branches. It shows that one report only: unlike the web tool there are no examples, modes, new or imported flows, and no adding blocks, so there is no blocks panel either. The file is self-contained - no server, no network, nothing uploaded - and a content security policy stops it loading or sending anything.
The Analysis view also shows the report's Trace completeness and the Findings from the code the trace made (they don't change as you edit). After any edit, Reset to report puts the report back as it was opened; Export JSON keeps the report's context, so an export reopens with its comparison against the original report. On a phone, a bar under the header shows the entry, whether the trace is complete, and report → now.
It opens a .md report written by sfcc-perf or a model JSON exported from the analyzer (not the --json summary, which show rejects), up to 5 MB, and checks it before writing the page. It replaces an existing .html only if sfcc-perf wrote it.
Before you share the page: it contains the whole report - every traced operation with its cartridge, file and line, service IDs and the relative links to your source - the same as the
.md. Share it where you'd share the code.
sfcc-perf show # the newest report in the report folder
sfcc-perf show perf/Cart-Show.md --out cart.html --no-open
sfcc-perf Product-Show --open # trace, write the .md and .html, open itIn CI (CI set) or with --no-open / SFCC_PERF_NO_OPEN=1 it only writes the file.
| Exit code | Meaning |
|---|---|
| 0 | OK |
| 1 | An entry couldn't be traced (unknown route, missing implementation, invalid options/config, …) |
| 3 | --strict (or "strict": true) and a trace is incomplete |
| 2 | A latency budget was exceeded |
When several apply, the first in this order wins. Under --strict, an incomplete trace is never checked against a budget: it fails with 3, and --json marks it "budgetSkipped": true.
Trace completeness
Every result says whether the tracer could follow everything it supports on the path. Cartridges on the cartridge path that aren't in the workspace, unresolved require()s and middleware, the call-depth limit, files with syntax errors, dynamic hook names, unresolvable dynamic templates and calls whose target is picked at runtime from something the tracer can't see (handlers[name]() on a parameter, list[0](), getHandler()() returning an unknown function) make a trace incomplete: the report shows a warning at the top and a Trace completeness section, and --json includes complete and coverageIssues. Without --strict an incomplete trace still exits 0 (with a warning on stderr); use --strict in CI so budgets are never checked against a partial model. A requested implementation that doesn't exist (an api.json endpoint, hook function or job step function that isn't exported) is always an error.
A missing cartridge counts because it may override what was traced. If some cartridges on the path live in another repository (a LINK cartridge, a shared plugin), list them in "externalCartridges" in .sfcc-perf.json: they're then reported as information, not as a gap.
Dispatch through a literal array or object the tracer can see is followed: handlers[0]() traces that element, and handlers[key]() / handlers.forEach(function (h) { h(); }) trace every member as equal-share alternatives, like switch cases.
Only files inside the --root folders are read: a source file that is a symbolic link to somewhere else is skipped and reported as an incomplete trace (outside-workspace), so tracing an unfamiliar repository can't read other files on your machine. An entry file you name explicitly is read wherever it is. Reports go to the project's report folder only if it's really inside the project, and never through a symbolic link; --out / --out-dir are used as given.
Complete means complete coverage of the constructs the tracer supports, not a guarantee about runtime behaviour: calls on objects it can't identify (a parameter's .process(), a platform object's methods it doesn't catalogue) are not followed and don't mark a trace incomplete.
CI example (GitHub Actions)
Commit the .sfcc-perf.json that sfcc-perf init writes (or pass --cartridge-path), and add the package as a dev dependency:
- uses: actions/setup-node@v4
with: { node-version: 20 }
- run: npm ci # sfcc-perf is in devDependencies
- run: npx sfcc-perf --all --strict --json > perf-summary.json
- uses: actions/upload-artifact@v4
if: always()
with: { name: sfcc-perf-reports, path: .sfcc-perf/reports }Without it in package.json, pin a version: npx --yes [email protected] --all --strict --cartridge-path "app_custom:app_storefront_base".
Config file
.sfcc-perf.json in the repository root is read by the CLI, the API (runAnalysis / createSession) and the VS Code extension. The file is validated: unknown keys, out-of-range numbers, unknown operation types or budget metrics, and latency profiles whose percentiles are out of order are all reported as errors.
{
"cartridgePath": "app_custom:int_payment:app_storefront_base",
"externalCartridges": ["int_payment"],
"conditionalProbability": 0.5,
"loopIterations": 5,
"cacheHitRate": 0.8,
"maxDepth": 20,
"scanTemplates": true,
"latencyOverrides": { "serviceFrameworkCall": { "avg": 350, "p95": 900, "p99": 1200 } },
"reportDirectory": "perf-reports",
"strict": true,
"entries": ["Product-Show", "Search-Show", "Cart-AddProduct", "api:loyalty/getPoints"],
"budgets": {
"Product-Show": { "avg": 400, "p95": 900 },
"*": { "p95": 1500 }
}
}Command-line flags override the file. reportDirectory must stay inside the project (use --out-dir for anywhere else). Budget metrics are avg, p95, p99 and max.
API
import fs from "node:fs";
import { runAnalysis, renderMarkdown, listEntryPoints, createSession, checkBudget } from "sfcc-perf";
const run = runAnalysis(["/path/to/repo"], "Product-Show"); // uses .sfcc-perf.json - or pass { cartridgePath: "…" }
run.analysis.averageLatency; // modeled average (ms)
run.analysis.p95; // path-weighted P95 score (see note below)
run.coverage.complete; // false if the tracer had to skip something
run.coverage.issues; // what was skipped and why
run.model.nodes; // the web tool's node/edge model
run.findings, run.staticFindings; // engine findings + code findings
fs.writeFileSync("Product-Show.md", renderMarkdown(run, { reportDir: "." }));
// Several entries with one parsed workspace (reads .sfcc-perf.json; options override it):
const { ws, tracer, opts } = createSession(["/path/to/repo"], { cartridgePath: "app_custom:app_storefront_base" });
for (const e of listEntryPoints(ws, tracer)) console.log(e.id, e.detail);Types are included. Options are validated at runtime; invalid values throw a ConfigError listing every problem, and a missing cartridge path throws MissingCartridgePathError (with the cartridge folders found). Each analyzeWith call starts from fresh trace state, so results don't depend on which entries a session analysed before.
The report
Summary (average, P50/P95/P99, best/worst case, critical path, cache hit vs miss, reference range), the middleware chain, every operation with its source file:line, how often it runs and its share, the top contributors, findings (the web tool's rules plus code findings: N+1 in loops, raw HTTPClient, writes in GET, uncached rendered pages, missing service timeouts, full catalog scans), the call tree, a Mermaid flow, assumptions and coverage, and the embedded model the web tool imports (between <!-- sfcc-perf-model:begin --> and <!-- sfcc-perf-model:end -->).
Open it with sfcc-perf show (above), or on the web analyzer click Import and choose the .md: either way it loads the traced flow, recomputes it with the same engine and shows a report → now comparison while you change values.
These are modeled numbers built from the web analyzer's illustrative latency defaults, not measurements. Use them to compare designs and find the expensive path, not as SLAs.
About P50/P95/P99: they are the web analyzer's path-weighted scores — each path's percentile profile weighted by how likely the path is — not statistical percentiles of the endpoint's latency distribution. A mix of fast and slow paths has a higher true P95 than this score. Budgets on
p95/p99compare against these scores.
Limits
Static analysis can't see runtime values: dynamic require() names, functions picked at runtime from containers it can't see, and calls on unknown receivers are skipped (each report's Trace completeness section lists what it couldn't resolve, except calls on unknown receivers, which are too common to flag). Branches use one assumed probability (if = p, else = 1 − p, switch cases equal shares) rather than real traffic. Very branchy models (over 20,000 distinct paths, or too much total path length to evaluate in about a second) are refused rather than evaluated slowly - the same limit as the web analyzer. Remote includes are counted at include cost only — trace the included route separately. Legacy XML pipelines are not supported.
Requirements
Node.js 18 or newer to run (tested on 18 and 25). Developing the package (tests, build) needs Node 20.19+ or 22.12+ because of the test tooling.
License
MIT
