Skip to content

perf(check): batch git subprocesses and auto-populate baseBranch on init#347

Merged
rhuanbarreto merged 7 commits into
mainfrom
perf/batch-git-subprocesses-and-auto-basebranch
May 25, 2026
Merged

perf(check): batch git subprocesses and auto-populate baseBranch on init#347
rhuanbarreto merged 7 commits into
mainfrom
perf/batch-git-subprocesses-and-auto-basebranch

Conversation

@rhuanbarreto

Copy link
Copy Markdown
Contributor

Summary

  • Parallelize independent git subprocess calls in getChangedFiles() and runChecks() via Promise.all, reducing archgate check latency by ~50-150ms (most impactful on Windows where process creation is expensive)
  • Auto-detect and save baseBranch to .archgate/config.json during archgate init, so subsequent check runs skip the 1-4 sequential git probe detection entirely
  • Add resolveBaseRef() test suite covering the full priority resolution chain: --staged--base → config → auto-detect

Closes #343, closes #346

Details

Git subprocess batching (#343)

getChangedFiles() ran staged and unstaged diff calls sequentially — now concurrent via Promise.all. In runChecks(), the changed files fetch and tracked files fetch were also sequential despite being independent — now started concurrently with synchronous work (filtering loadResults, resolving filterFiles) interleaved while the git I/O runs.

baseBranch auto-population (#346)

The baseBranch config field, reader (getConfiguredBaseBranch), and consumer (resolveBaseRef) already existed but nothing populated the field. initProject() now calls detectBaseRef() after directory creation and saves the result to config.json. The detection is:

  • Non-fatal — wrapped in try/catch, logs debug on failure
  • Idempotent — skips if baseBranch is already configured (safe for re-init)
  • Git-optional — gracefully no-ops when not in a git repository

Test plan

  • resolveBaseRef() tests: staged short-circuit, explicit base priority, configBase priority, fallback to detectBaseRef, non-git fallback
  • baseBranch init tests: auto-detection saves to config, re-init preserves existing value, non-git directory skips
  • Existing getChangedFiles and detectBaseRef tests still pass (behavior unchanged)
  • bun run validate passes (lint, typecheck, format, test, ADR check, knip, build)
  • All 27 ADR rules pass

…nit (#343, #346)

Parallelize independent git subprocess calls to reduce `archgate check`
latency, and auto-detect the base branch during `archgate init` so
subsequent checks skip the 1-4 probe detection entirely.

- Parallelize staged + unstaged diff calls in `getChangedFiles()` via
  `Promise.all` (~25ms saved on Windows per call)
- Parallelize `changedFiles` + `trackedFiles` fetch in `runChecks()`,
  interleaving synchronous work while git I/O runs
- Auto-detect and save `baseBranch` to `.archgate/config.json` during
  `initProject()`, completing the existing config plumbing
- Add `resolveBaseRef()` test suite covering priority resolution
- Add baseBranch auto-detection tests (save, idempotent re-init, non-git)

Closes #343, closes #346

Signed-off-by: Rhuan Barreto <rhuan@barreto.work>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 25, 2026

Copy link
Copy Markdown

Deploying archgate-cli with  Cloudflare Pages  Cloudflare Pages

Latest commit: bd5b509
Status: ✅  Deploy successful!
Preview URL: https://cc9e02ab.archgate-cli.pages.dev
Branch Preview URL: https://perf-batch-git-subprocesses.archgate-cli.pages.dev

View logs

@github-actions

github-actions Bot commented May 25, 2026

Copy link
Copy Markdown
Contributor

Code Coverage

Metric Value
Lines 90.0% (6510 / 7231)
Platforms Linux + Windows

Full HTML report available in workflow artifacts.

Per-directory breakdown
Directory Coverage Lines
src/commands/ 88.1% 2069 / 2348
src/engine/ 93.1% 1193 / 1282
src/formats/ 100.0% 141 / 141
src/helpers/ 89.8% 3107 / 3460

rhuanbarreto and others added 6 commits May 25, 2026 13:50
Add baseBranch to the configuration reference (EN + PT-BR) with type,
default, description, and manual override example. Document the init
command's base branch auto-detection behavior in both locales. Update
the config.json intro to reflect that init now creates the file for
baseBranch (not just custom domains).

Signed-off-by: Rhuan Barreto <rhuan@barreto.work>
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
When resolveBaseRef() falls back to auto-detection and succeeds, save
the detected branch to .archgate/config.json so all subsequent runs
skip the 1-4 git probe detection entirely. This benefits users who
never run archgate init — the optimization kicks in after the first
check invocation.

The lazy-save is non-fatal (try/catch) so read-only filesystems and
CI environments are unaffected. It also preserves any existing
baseBranch value to avoid overwriting manual configuration.

Signed-off-by: Rhuan Barreto <rhuan@barreto.work>
…ogic

The same detect → check config → save pattern was duplicated in
init-project.ts and git-files.ts. Extract into ensureBaseBranch()
in project-config.ts (where the other baseBranch helpers live).

Both init (eager) and resolveBaseRef (lazy) now call the same
function, which accepts detectBaseRef as a parameter to avoid a
circular dependency between engine and helpers.

Signed-off-by: Rhuan Barreto <rhuan@barreto.work>
The buildReviewContext tests used bare rmSync for temp dir cleanup,
which fails intermittently on Windows when git processes haven't
fully released file locks. Switch to safeRmSync (retry with backoff),
matching the pattern already used in git-files.test.ts and
init-project.test.ts.

Signed-off-by: Rhuan Barreto <rhuan@barreto.work>
@rhuanbarreto rhuanbarreto merged commit d0aa6b2 into main May 25, 2026
12 checks passed
@rhuanbarreto rhuanbarreto deleted the perf/batch-git-subprocesses-and-auto-basebranch branch May 25, 2026 13:19
@archgatebot archgatebot Bot mentioned this pull request May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: cache base-branch detection result per repository perf: batch git subprocess calls in check command

1 participant