Visitar URL original
Very slow initialization of `codeclimate analyze` unless all `node_modules` directories are not made available to Docker · Issue #912 · codeclimate/codeclimate · GitHub
The Wayback Machine - https://web.archive.org/web/20201018232253/https://github.com/codeclimate/codeclimate/issues/912
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Very slow initialization of `codeclimate analyze` unless all `node_modules` directories are not made available to Docker #912

Open
jonahwh opened this issue Apr 19, 2019 · 4 comments
Assignees

Comments

@jonahwh
Copy link

@jonahwh jonahwh commented Apr 19, 2019 •

This seems similar to #238

When running codeclimate analyze (or just directly invoking docker) in a project with any node_modules folders, the command hangs for a while (usually in my case, just over 30 seconds) before actually starting analysis.

If we do any of the following, the analysis runs as speedily as expected:

  • Remove all node_modules folder in the project
  • Remove Read access from all node_modules folders
  • Mount empty directories to the node_modules folder, via docker flags, e.g.
docker run \
  --rm \
  --env CODECLIMATE_CODE="$PWD" \
  --volume "$PWD":/code \
  --volume /var/run/docker.sock:/var/run/docker.sock \
  --volume /tmp/cc:/tmp/cc \
  # this is the magic flag that "fixes" the issue
  --volume /code/node_modules \
  codeclimate/codeclimate analyze)

- "**/node_modules/" is in our exclude_patterns setting in .codeclimate.yml, and even if we wait for codeclimate to start with all the node_modules folders intact, the engines don't run on them, but it seems the excluded files are still being scanned before any engines start up.

Some output:

Without cleaning up node_modules

 ❯ docker run \
  --rm \
  --env CODECLIMATE_CODE="$PWD" \
  --env CODECLIMATE_DEBUG \
  --volume "$PWD":/code \
  --volume /var/run/docker.sock:/var/run/docker.sock \
  --volume /tmp/cc:/tmp/cc \
  codeclimate/codeclimate analyze
I, [2019-04-19T18:32:50.980276 #1]  INFO -- : starting engine structure
D, [2019-04-19T18:33:27.439929 #1] DEBUG -- : /config.json content:

~37 seconds

With cleaning up node_modules by any method mentioned above

❯ docker run \
  --rm \
  --env CODECLIMATE_CODE="$PWD" \
  --env CODECLIMATE_DEBUG \
  --volume "$PWD":/code \
  --volume /var/run/docker.sock:/var/run/docker.sock \
  --volume /tmp/cc:/tmp/cc \
  --volume /code/node_modules \
  codeclimate/codeclimate analyze
I, [2019-04-19T18:26:12.105992 #1]  INFO -- : starting engine structure
D, [2019-04-19T18:26:12.263300 #1] DEBUG -- : /config.json content: 

<1 second

@wfleming
Copy link
Member

@wfleming wfleming commented Apr 20, 2019

Hi @jonahwh, can you please share the contents of your .codeclimate.yml? It would be helpful to see all of your exclude patterns to be able to better understand what might be causing this issue.

@jonahwh
Copy link
Author

@jonahwh jonahwh commented Apr 20, 2019

version: "2"
checks:
  argument-count:
    enabled: true
    config:
      threshold: 4
  complex-logic:
    enabled: true
    config:
      threshold: 4
  file-lines:
    enabled: true
    config:
      threshold: 250
  method-complexity:
    enabled: true
    config:
      threshold: 5
  method-count:
    enabled: true
    config:
      threshold: 20
  method-lines:
    enabled: true
    config:
      threshold: 25
  nested-control-flow:
    enabled: true
    config:
      threshold: 4
  return-statements:
    enabled: true
    config:
      threshold: 4
  similar-code:
    enabled: true
    config:
      threshold: #language-specific defaults. overrides affect all languages.
  identical-code:
    enabled: true
    config:
      threshold: #language-specific defaults. overrides affect all languages.
plugins:
  duplication:
    enabled: true
  eslint:
    enabled: true
    channel: "eslint-5"
exclude_paths:
  - "app/build"
  - "**/node_modules/"
  - "**/generated/"
  - "app/src/serviceWorker.ts"
@wfleming
Copy link
Member

@wfleming wfleming commented May 22, 2019

@jonahwh apologies for my very delayed reply here, I haven't had much time to look at this.

Unfortunately I'm having trouble reproducing this. I do have one shot-in-the-dark suggestion: instead of using **/node_modules in your pattern, could you just exclude node_modules/? (Or if you have several node_modules directories you're trying to exclude, could you list each of them explicitly without using wildcards?)

The reason I suggest this is that if you have a particularly large/deep node_modules directory, globbing for **/node_modules means Ruby's Dir.glob will walk the entire directory structure of your project looking for node_modules, and if your project is particularly large or your node_modules install is particularly large, that's wasted time. Our CLI processes exclude patterns by using Ruby stdlib's Dir.glob to expand the patterns fully and then exclud the matches, so on large projects ** can slow down processing exclusions, although your case is unusually slow.

That being said, 30 secs to walk a directory tree would have to be a very, very large directory tree. So if that doesn't help, I'd like to ask a few follow up questions.

  • I presume the project you're working on is private, but would it be possible for you to share a modified version of your package.json (with project details removed but the same dependencies) to help me try and reproduce the slowness?
  • What operating system are you using? If MacOS, are you using Docker for Mac, and if so what version? (Docker for Mac's filesystem handling has some [significant performance issues](https://docs.docker.com/docker-for-mac/osxfs/#performance-issues-solutions-and-roadmap in certain cases))
@zharikovpro
Copy link

@zharikovpro zharikovpro commented Dec 14, 2019

I have faced the same issue. For somewhat reason, global exclusion pattern didn't help to deal with node_modules. The workaround is to add explicit paths for duplication engine:

version: "2"
exclude_patterns:
  - "**/node_modules/"
  - "**/vendor/"
  - "**/app/locales/"
  - "**/db/schema.rb"
  duplication:
    enabled: true
    exclude_patterns:
      # global config is not enough for somewhat reason
      # list each nodes_modules path separately, to speed up local analyzes
      - "frontend/smhw-frontend/node_modules/"
      - "frontend/smhw-frontend/bower_components/"
      - "frontend/admin-frontend/node_modules/"
      - "frontend/admin-frontend/bower_components/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.