GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — refactor: stop compiling the AI catalog and loading urllib at import by shenxianpeng · Pull Request #693 · commit-check/commit-check

Conversation

@shenxianpeng

@shenxianpeng shenxianpeng commented Nov 11, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

What

Importing the CLI no longer compiles the AI signature catalog or loads urllib and importlib.metadata. Each is loaded the first time it is used.

Every pre-commit hook run, and every commit the Action or the App checks, starts a fresh interpreter, so import cost is paid once per commit. It had grown by about half since 2.15 without anything flagging it. CodSpeed times test bodies after everything is already imported, so it cannot see this cost.

  • AI signatures: AiSignaturePattern keeps its source and flags and compiles regex on first use. KnownAiTool keeps names and compiles name_pattern on first use. ALL_PATTERNS is built when something asks for it. ai_attribution is off by default, so most runs now compile none of the catalog. With a policy set, the scanner still builds only its grouped alternations, as before; the per-pattern regexes were used only by tests.
  • inherit_from URLs: the HTTPS-only opener moves to commit_check/_https.py and is imported only when a parent config is fetched. urllib.request and urllib.error together cost more than the rest of the CLI's own imports.
  • --version: __version__ is read from the package metadata only when something asks for it. from commit_check import __version__ still works, which matters for commit-check-mcp.

Before vs after

CPU instructions per run (valgrind callgrind, deterministic, wheel installs of main and this branch). The Python interpreter alone is 38M.

Command main this PR Change
commit-check -m <file> 474M 242M −49%
commit-check -b 475M 237M −50%
commit-check -m -b -n -e 483M 250M −48%
-m <file> with ai_attribution = "forbid" 541M 312M −42%
commit-check --version 469M 292M −38%

Wall clock, median of 40 runs:

Command main this PR
commit-check -m <file> 123 ms 71 ms
commit-check -m -b -n -e 152 ms 104 ms

For reference, 2.15.0 measured 317M for -m <file>, so this also takes startup below where it was before the AI rules were added.

Regexes compiled at import: 193 before, 29 after.

Keeping it from coming back

tests/startup_test.py imports the CLI in a fresh interpreter. It fails if that import loads importlib.metadata, urllib, http.client or ssl, compiles any AI signature pattern, or compiles more than 40 regexes. One new benchmark, test_compiling_the_catalog_cold, measures what the first AI scan of a run pays. CodSpeed will flag it as the catalog grows.

Checks

  • Full test suite passes; coverage stays at 100% lines and branches.
  • ruff check, ruff format --check and mypy are clean.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@shenxianpeng
shenxianpeng requested a review from a team as a code owner November 11, 2026 04:38
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor
Pre-merge checks: Passed 1 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Title check Pending This assessment has not completed. The check will be retried on the next pre-merge check run.
Passed Passed checks: 1 passed

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

  • X
  • Mastodon
  • Reddit
  • LinkedIn
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the enhancement New feature or request label Nov 11, 2026
@shenxianpeng shenxianpeng self-assigned this Nov 11, 2026
@shenxianpeng
refactor: stop compiling the AI catalog and loading urllib at import
4e1c012
Every pre-commit hook run, and every commit the Action or the App checks,
starts a fresh interpreter, so import work is paid once per commit. It had
grown by about half since 2.15: importing the CLI compiled all 160+ AI
signature regexes, although ai_attribution is off by default, and loaded
urllib and importlib.metadata, which only inherit_from URLs and --version
use.

- Signature patterns keep their source and compile on first use.
  ALL_PATTERNS is built when something asks for it.
- The HTTPS-only opener moves to commit_check._https and is imported when
  a parent config is fetched.
- __version__ is read from the package metadata when it is asked for.

CPU instructions for `commit-check -m <file>` drop from 478M to about
250M (python itself is 75M). The benchmarks time test bodies after
everything is imported, so they could not see this; startup_test.py now
fails if import pulls these modules back in or compiles the catalog, and
one benchmark measures the catalog's cold compile as it grows.
@shenxianpeng
shenxianpeng force-pushed the perf/lazy-ai-signatures branch from 9fd940d to 4e1c012 Compare November 11, 2026 04:39
@shenxianpeng shenxianpeng changed the title perf: stop compiling the AI catalog and loading urllib at import refactor: stop compiling the AI catalog and loading urllib at import Nov 11, 2026
@sonarqubecloud

sonarqubecloud Bot commented Nov 11, 2026

Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@codecov

codecov Bot commented Nov 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (ab14f96) to head (4e1c012).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #693   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           14        15    +1     
  Lines         2552      2587   +35     
  Branches       499       502    +3     
=========================================
+ Hits          2552      2587   +35     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@shenxianpeng shenxianpeng added refactor Refactor source code and removed enhancement New feature or request labels Nov 11, 2026
@codspeed

codspeed Bot commented Nov 11, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Merging this PR will improve performance by ×2.1

2 warnings, 1 note

⚠️ 138 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ 2 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

ℹ️ This run is excluded from the branch history

This commit was force-pushed, so this run no longer appears in the branch's performance history.

⚡ 2 improved benchmarks
✅ 682 untouched benchmarks
🆕 1 new benchmark
⏩ 131 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ test_constants_set_when_color_on 7.1 ms 3.4 ms ×2.1
⚡ test_constants_empty_when_color_off 7.3 ms 3.5 ms ×2.1
🆕 test_compiling_the_catalog_cold N/A 107.9 ms N/A

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing perf/lazy-ai-signatures (9fd940d) with main (03d6f61)2

Open in CodSpeed

Footnotes

  1. 131 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on main (ab14f96) during the generation of this report, so 03d6f61 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@shenxianpeng
shenxianpeng merged commit bd713de into main Nov 11, 2026
33 of 34 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@shenxianpeng
shenxianpeng deleted the perf/lazy-ai-signatures branch November 11, 2026 05:07
@shenxianpeng shenxianpeng added chore and removed refactor Refactor source code labels Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@shenxianpeng shenxianpeng

Labels

chore

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@shenxianpeng
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.