Skip to content

Optimization: don't call identify unless necessary #3729

Description

@vries

search you tried in the issue tracker

I looked at the title of all open issues, and searched for "identify types" in open/closed issues

describe your actual problem

Consider the following .pre-commit-config.yaml:

repos:
  - repo: local
    hooks:
    - id: try
      name: try
      language: unsupported
      entry: 'true'
      types: []
      types_or: []
      exclude_types: []

combined with the binutils-gdb repo, a repo with 44782 files.

For this hook, types are not used so there's no need to call identify, but it still is.

If identify is called (without #3725), we have:

$ for f in $(seq 1 5); do \
      ( time pre-commit run try --all-files > /dev/null ) 2>&1 | grep real; \
    done
real    0m0,634s
real    0m0,641s
real    0m0,638s
real    0m0,643s
real    0m0,642s

And if identify is not called (with #3725) we have instead:

real    0m0,244s
real    0m0,242s
real    0m0,240s
real    0m0,244s
real    0m0,245s

pre-commit --version

4.6.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions