Skip to content

perf(core): reduce redundant formatter traversal work#960

Merged
mk3008 merged 24 commits into
mainfrom
codex/renderer-parameter-collection-fast-path
Jul 12, 2026
Merged

perf(core): reduce redundant formatter traversal work#960
mk3008 merged 24 commits into
mainfrom
codex/renderer-parameter-collection-fast-path

Conversation

@mk3008

@mk3008 mk3008 commented Jul 11, 2026

Copy link
Copy Markdown
Owner

Summary

  • Avoid unnecessary comment-subtree traversal for non-logical print tokens while preserving formatted SQL and comment layout.
  • Collect formatter parameters during the existing token-build visit, removing the unconditional second AST traversal.
  • Add a phase-isolated paired benchmark foundation and document rejected R3–R5 candidates so identical micro-optimizations are not reintroduced without new evidence.
  • Require complete, successful Stage 1 screen evidence before a Stage 2 confirmation can spawn benchmark processes.
  • Add two rawsql-ts patch changesets for the adopted R1 and R2 improvements.

Verification

  • pnpm --filter rawsql-ts test — 242 files / 2,467 tests passed / 1 skipped for R2.
  • pnpm --filter rawsql-ts build and pnpm --filter rawsql-ts lint — passed.
  • pnpm --filter rawsql-ts benchmark and pnpm demo:complex-sql — passed for formatter behavior changes.
  • pnpm test:ast-paired-runner — 80 tests passed, including independently named malformed Stage 1 screen-evidence cases that reject before any benchmark spawn and leave the candidate record unchanged.
  • Paired Stage 3 semantic comparison — R1 and R2 each matched 42/42 sinks.
  • pnpm changeset status — two rawsql-ts patch changesets.
  • git diff --check origin/main...HEAD — passed.

Merge Readiness

  • No baseline exception requested.
  • Baseline exception requested and linked below.

Tracking issue: not required; performance maintenance work has no linked issue.
Scoped checks run: core test/build/lint, formatter benchmark, complex SQL demo, paired-runner tests, paired Stage 1–3 semantic comparisons, changeset status, and diff check.
Why full baseline is not required: full workspace typecheck/test/build/lint ran through commit hooks; no baseline exception is requested.

Self Review

Self-review workflow: two-cycle self-review plus parent acceptance review for each candidate.
Self-review result: no merge blocker remains for R1/R2; R3/R4/R5 adverse or inconclusive evidence is retained and excluded from adopted product changes.
Concept-review workflow: packages/core DBMS-neutral analyzer and formatter boundary review.
Concept-review result: no public API, SQL grammar, driver, QuerySpec, ZTD, CLI, or scaffold boundary violation found.

CLI Surface Migration

  • No migration packet required for this CLI change.
  • CLI/user-facing surface change and migration packet completed.

No-migration rationale: no CLI-facing file or user command contract changed.
Upgrade note: none; this is a backward-compatible internal formatter/analyzer performance maintenance change.
Deprecation/removal plan or issue: none; no public API or CLI surface is removed.
Docs/help/examples updated: benchmark protocol documentation and rejected-candidate findings were added; CLI help and examples are unaffected.
Release/changeset wording: two rawsql-ts patch changesets describe reduced rendering traversal and redundant parameter-collection work without a universal speed claim.

Scaffold Contract Proof

  • No scaffold contract proof required for this PR.
  • Scaffold contract proof completed.

No-proof rationale: no scaffold source, template, or generated artifact behavior changed.
Non-edit assertion: scaffold-related paths are absent from the PR diff.
Fail-fast input-contract proof: not applicable because no scaffold input contract changed.
Generated-output viability proof: not applicable because no scaffold output is generated by this PR.

Summary by CodeRabbit

  • Performance

    • Reduced redundant work during SQL parameter collection and rendering.
    • Preserved formatted SQL output and comment layout.
  • Bug Fixes

    • Maintained parameter ordering, indexes, names, conflict handling, and original placeholder formatting across supported parameter styles.
    • Preserved compatibility with existing parameter-formatting results.
  • Documentation

    • Added benchmark guidance, reference data, and recorded performance findings for SQL analysis and rendering.

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@mk3008, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 23 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ea31c931-723f-4155-8fef-e3d868aec036

📥 Commits

Reviewing files that changed from the base of the PR and between 1c6cb14 and 9684e22.

📒 Files selected for processing (5)
  • benchmarks/ast-analysis-paired-runner.ts
  • benchmarks/ast-analysis-phase-benchmark.ts
  • docs/bench/ast-analysis-paired-runner.md
  • docs/bench/ast-analysis-phase-p0-reference.json
  • scripts/ast-analysis-paired-runner.test.ts
📝 Walkthrough

Walkthrough

This change adds AST phase benchmarking and a staged paired-runner workflow with persisted evidence, while optimizing SQL parameter collection and comment traversal. It also adds validation tests, benchmark records, reference data, documentation, and release changesets.

Changes

AST benchmark workflow

Layer / File(s) Summary
Benchmark protocol and evidence contracts
docs/bench/ast-analysis-*.md, docs/bench/*.json, docs/bench/ast-analysis-benchmark-candidate-records.jsonl
Defines benchmark phases, staged decisions, evidence requirements, reference timings, candidate records, and rejected-candidate findings.
Phase benchmark harness
benchmarks/ast-analysis-phase-benchmark.ts
Runs selected AST and renderer phases over tracked and synthetic SQL corpora, validates semantic sinks, computes timing statistics, and writes reports.
Paired benchmark orchestration
benchmarks/ast-analysis-paired-runner.ts
Validates manifests and prior records, executes baseline/candidate pairs, compares semantic outputs, classifies results, and appends summary evidence.
Benchmark wiring and validation
package.json, scripts/ast-analysis-paired-runner.test.ts
Adds benchmark commands and tests admission failures, ordering, semantic mismatches, retained records, and full-profile inheritance.

Formatter traversal optimizations

Layer / File(s) Summary
Inline parameter collection
.changeset/calm-formatters-collect-once.md, packages/core/src/parsers/SqlPrintTokenParser.ts, packages/core/tests/transformers/SqlFormatter.parameter-collection-fast-path.test.ts
Collects parameters during token parsing, orders them by assigned index, and verifies parameter styles, conflicts, source spelling, and legacy output.
Comment predicate short-circuit
.changeset/reduce-printer-comment-traversal.md, packages/core/src/transformers/SqlPrinter.ts, packages/core/tests/transformers/CommentStyle.comprehensive.test.ts
Checks logical operator type before traversing comment descendants and verifies non-logical tokens are not traversed.

Estimated code review effort: 5 (Critical) | ~120 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant PairedRunner
  participant PhaseBenchmark
  participant JSONLRecord
  CLI->>PairedRunner: provide benchmark manifest
  PairedRunner->>PhaseBenchmark: execute baseline and candidate runs
  PhaseBenchmark-->>PairedRunner: return reports and semantic sinks
  PairedRunner->>PairedRunner: classify deltas and mismatches
  PairedRunner->>JSONLRecord: write summary and append candidate record
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: reducing redundant formatter traversal work in core formatting.
Description check ✅ Passed The description follows the template and fills the required sections with summary, verification, readiness, review, migration, and proof details.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/renderer-parameter-collection-fast-path

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (1)
benchmarks/ast-analysis-phase-benchmark.ts (1)

875-893: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Exclusive-write flag (wx) is only applied to the explicit --output-file path.

The --output-file branch uses flag: 'wx' to prevent silently clobbering an existing raw artifact (matching the append-only evidence requirement described in the paired-runner docs), but the default auto-generated path (Line 891) writes without that flag. Collision risk is low given the timestamp+pid naming, but adding the same exclusivity guard would make the two branches consistent.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@benchmarks/ast-analysis-phase-benchmark.ts` around lines 875 - 893, Update
writeReport so the default generated output path uses the same exclusive-write
mode as the explicit --output-file branch. Preserve the existing generated
filename and serialization behavior while passing the equivalent wx flag to its
fs.writeFileSync call.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@benchmarks/ast-analysis-paired-runner.ts`:
- Around line 803-823: Update the commandsComplete validation in the
confirmation command check to verify the complete invocation, matching the
screen-evidence validation: require the expected command and cwdRole, and ensure
command.args exactly matches the expected --profile, --phases, --condition,
--candidate-id, --pair-index, and --output-file values rather than checking only
selected arguments.
- Around line 560-571: Update the full-profile predecessor-screen validation
around validateConfirmationRecord to validate the complete Stage 1 evidence
contract, including the required two commands, artifacts, and rows, before
admitting Stage 3. Reuse the existing Stage 1 validation path or equivalent
checks rather than only validating inherited metadata, while preserving the
missing-screen error behavior.
- Around line 924-930: Add a stage-appropriate timeout to the spawnSync
invocation in the paired-run execution flow, and handle timeout expiry as a
failed run so the loop continues to produce summary and failure artifacts.
Preserve the existing command, arguments, environment, and normal success/error
handling.

In `@scripts/ast-analysis-paired-runner.test.ts`:
- Line 1150: Update the failure-retention tests around runPairedBenchmark to
stub the benchmark subprocess via spawnSync, returning a nonzero result instead
of executing the real benchmark. Keep the tests’ assertions and
incomplete-checkout setup focused on retention behavior while making them
independent of benchmark layout changes.

---

Nitpick comments:
In `@benchmarks/ast-analysis-phase-benchmark.ts`:
- Around line 875-893: Update writeReport so the default generated output path
uses the same exclusive-write mode as the explicit --output-file branch.
Preserve the existing generated filename and serialization behavior while
passing the equivalent wx flag to its fs.writeFileSync call.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f31c865e-0442-4db9-ad2d-eead3d9af524

📥 Commits

Reviewing files that changed from the base of the PR and between 1a26e94 and 1c6cb14.

📒 Files selected for processing (16)
  • .changeset/calm-formatters-collect-once.md
  • .changeset/reduce-printer-comment-traversal.md
  • benchmarks/ast-analysis-paired-runner.ts
  • benchmarks/ast-analysis-phase-benchmark.ts
  • docs/bench/ast-analysis-benchmark-candidate-records.jsonl
  • docs/bench/ast-analysis-benchmark-measurement-efficiency.md
  • docs/bench/ast-analysis-paired-runner.md
  • docs/bench/ast-analysis-phase-benchmark.md
  • docs/bench/ast-analysis-phase-p0-reference.json
  • docs/bench/ast-analysis-rejected-candidate-findings.md
  • package.json
  • packages/core/src/parsers/SqlPrintTokenParser.ts
  • packages/core/src/transformers/SqlPrinter.ts
  • packages/core/tests/transformers/CommentStyle.comprehensive.test.ts
  • packages/core/tests/transformers/SqlFormatter.parameter-collection-fast-path.test.ts
  • scripts/ast-analysis-paired-runner.test.ts

Comment thread benchmarks/ast-analysis-paired-runner.ts
Comment thread benchmarks/ast-analysis-paired-runner.ts
Comment thread benchmarks/ast-analysis-paired-runner.ts
Comment thread scripts/ast-analysis-paired-runner.test.ts
@mk3008
mk3008 merged commit 99d0050 into main Jul 12, 2026
10 checks passed
@mk3008
mk3008 deleted the codex/renderer-parameter-collection-fast-path branch July 12, 2026 07:30
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.

1 participant