Code Monkey home page Code Monkey logo

Comments (10)

jgirardet avatar jgirardet commented on June 17, 2024

hi @asottile .
Indeed using tempfile is not a big performance issue. I tested.
The main problem. is the pre-commit running time.

@RonnyPfannschmidt asked me for using same version of black (in editor and command line) via pre-commit.
I see 2 ways of doing it keeping run time as slow as possible:

  • pre-commit could have a "skip-pre-commit" ;-) option to directly run the hook, skipping all the precommit stuf. if it accepts arguments we are ultimate.
  • expose the hook path via a "hook info" option or something like this so we could run directly the right executable from pre-commit repo.

from pre-commit.com.

RonnyPfannschmidt avatar RonnyPfannschmidt commented on June 17, 2024

@jgirardet would it be sufficient to limit the pre-commit hook run to only/exactly the black hook, if the env is cached already that might be really quick

from pre-commit.com.

asottile avatar asottile commented on June 17, 2024

pre-commit could have a "skip-pre-commit" ;-) option to directly run the hook, skipping all the precommit stuf. if it accepts arguments we are ultimate.

I'm not sure what you mean here, that's essentially what pre-commit run <hookid> --files ... is

from pre-commit.com.

jgirardet avatar jgirardet commented on June 17, 2024

the idea was to run black via precommit but without the whole bunch of things that pre commit do, to save some time.

from pre-commit.com.

asottile avatar asottile commented on June 17, 2024

there isn't really anything that pre-commit does beyond collect the args and subprocess, last time I profiled it it essentially boiled down to:

  1. 5%: python interpreter startup
  2. 80%: import of pkg_resources module
  3. 1%: subprocess to determine git rev-parse --show-toplevel
  4. 1%: parsing yaml configurations
  5. 1%: subprocess git ls-files to cross reference --files
  6. 1% subprocess git diff to know when files change

And factoring out pkg_resources isn't easy.

from pre-commit.com.

asottile avatar asottile commented on June 17, 2024

some rough numbers:

$ time ~/opt/venv/bin/python -c ''

real	0m0.028s
user	0m0.020s
sys	0m0.008s

$ time ~/opt/venv/bin/python -c 'import pre_commit.main'

real	0m0.185s
user	0m0.169s
sys	0m0.017s

$ time pre-commit run echo --verbose --files setup.py
[echo] echo..............................................................Passed
hookid: echo

setup.py


real	0m0.204s
user	0m0.181s
sys	0m0.025s

from pre-commit.com.

jgirardet avatar jgirardet commented on June 17, 2024

thank you for your answers @asottile

from pre-commit.com.

asottile avatar asottile commented on June 17, 2024

Note that pkg_resources will be factored out in the next release: pre-commit/pre-commit#840

from pre-commit.com.

RonnyPfannschmidt avatar RonnyPfannschmidt commented on June 17, 2024

@asottile great job, thanks πŸ‘

from pre-commit.com.

asottile avatar asottile commented on June 17, 2024

feel free to send PRs for editor integrations -- going to close this since there isn't really anything actionable at the moment

from pre-commit.com.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.