Skip to content

Make the git hooks fast: no analysis on commit, only what a push affects - #38

Merged
burhankhanzada merged 1 commit into
mainfrom
chore/faster-hooks
Oct 4, 2026
Merged

burhankhanzada merged 1 commit into
mainfrom
chore/faster-hooks

Conversation

@burhankhanzada

Copy link
Copy Markdown
Member

pre-commit no longer analyzes: dart analyze --fatal-infos takes 40–55 s here even for one file, which gets a hook skipped with --no-verify. The IDE shows the same findings, and pre-push analyzes before anything leaves the machine. Templates are synced into pubspec.yaml only when a template changed (was a dart run on every commit, ~45 s when native hooks were stale).

pre-push checks only what the pushed commits can affect, compared with the remote ref (or, for a new branch, where it left main):

  • docs and workflows alone: nothing;
  • app code, tests, packages, assets, tools, dependencies or lint setup: analysis + tests;
  • packages/: the package checks too (packages can't import the app; an app-only push went ~155 s → ~95 s);
  • no usable base: everything.

Checks still run one at a time: side by side was slower on an 8-core Mac.

Tested locally: a synthetic docs-only commit skips in under a second (pushed both as an existing and as a new branch); a code commit (#28's) runs the full analysis and tests; both hooks pass sh -n. Pushing this branch itself skipped, as it should. CONTRIBUTING.md and setup_hooks.sh describe the new behaviour.

🤖 Generated with Claude Code

pre-commit no longer analyzes. `dart analyze --fatal-infos` takes 40-55 s
here even for one file, mostly loading the analyzer plugins, which is a
commit you learn to skip with --no-verify. The IDE shows the same
findings as you type, and pre-push analyzes before anything leaves the
machine. Templates are synced into pubspec.yaml only when a template
changed, instead of a `dart run` on every commit (~45 s whenever the
native hooks were stale).

pre-push checks only what the pushed commits can affect, compared with
the remote ref or, for a new branch, where it left main:

- docs and workflows alone run nothing;
- the app is analyzed and tested when its code, tests, packages, assets,
  tools, dependencies or lint setup changed;
- the packages are checked only when packages/ changed, since they
  cannot import the app (an app-only push: ~155 s to ~95 s);
- no usable base checks everything.

The checks still run one at a time: measured on an 8-core Mac, running
them side by side was slower, as each already uses every core.

CONTRIBUTING.md and setup_hooks.sh describe the new behaviour.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@burhankhanzada
burhankhanzada merged commit 841e915 into main Oct 4, 2026
21 checks passed
@burhankhanzada
burhankhanzada deleted the chore/faster-hooks branch October 4, 2026 16:09
@burhankhanzada burhankhanzada mentioned this pull request Oct 4, 2026
2 tasks done
burhankhanzada added a commit that referenced this pull request Oct 4, 2026
## What and why

Follow-up to #38. `dart fix --apply` was most of what was left of a
commit: it analyzes the whole project (~9 s, the same for one staged
file as for all of them) to apply a handful of automated fixes, and it
rewrote files that were not staged.

The lints it fixes still show in the IDE and block at pre-push, and
`dart fix --apply` is one command to run when they come up. A commit of
staged Dart is now import sorting and formatting — about a second.

## How it was verified

- [x] `sh -n` on the hook
- [x] This branch's own commit and push went through the hooks: the
commit (no Dart staged) took 0 s, and the push — only `.githooks/` and
`setup_hooks.sh` changed — skipped its checks in 2 s, which is #38 doing
what it says

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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