Skip to content

Batch phpcs into two invocations: one for new files, one for old#114

Open
sirbrillig wants to merge 1 commit intotrunkfrom
two-batch-phpcs-invocations
Open

Batch phpcs into two invocations: one for new files, one for old#114
sirbrillig wants to merge 1 commit intotrunkfrom
two-batch-phpcs-invocations

Conversation

@sirbrillig
Copy link
Copy Markdown
Owner

@sirbrillig sirbrillig commented Apr 21, 2026

Fixes #115

Summary

Alternative to #110, which batches all phpcs calls into a single invocation.

This approach uses two separate phpcs batch calls instead of one combined call:

  1. First batch: Run phpcs on all new (modified) file versions at once
  2. Second batch: Run phpcs on all old (unmodified) file versions at once — but only for files that have new phpcs messages

Key difference from #110

The single-batch approach (#110) pre-determines which old files need scanning before the new-file results are known, which means it sometimes scans old versions of files that turn out to have no new messages (wasted work).

This two-batch approach waits until the new-file results are in before deciding which old versions to scan, preserving the existing per-file optimization of skipping old-version scans for clean files.

Trade-offs vs #110

  • Simpler: Each batch method returns array<string,string> instead of array{new:..., old:...}
  • Smarter: Never scans old versions of files with no new messages
  • Two startup costs instead of one when all files have messages (minor overhead)

Performance

Measured with benchmark.sh on 10 staged PHP files (PSR2 standard, 10 runs):

Mean Relative
trunk: 20 phpcs calls 6.94 s ± 0.61 s 1.00×
two-batch (this branch): 2 phpcs calls 3.57 s ± 0.29 s 1.95× faster

… old

Instead of running phpcs per-file (2N invocations for N files), batch all
new (modified) file versions into one phpcs call, then batch all old
(unmodified) file versions into a second phpcs call.

This preserves the existing optimization of skipping the old-version scan
entirely for files that have no new phpcs messages, since the old-version
batch is only assembled after the new-version results are known.
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.

Improve performance by reducing the number of phpcs calls

1 participant