Skip to content

Improve perfomance during pre-commit --all (-a) run #309

@MaxymVlasov

Description

@MaxymVlasov

Some hooks recursively check all files in provided dir.

So performance degradation exists only in the pre-commit run --all situation, because it will provide all existing repo files to hook:

# consume modified files passed from pre-commit so that
# terrascan runs against only those relevant directories
for file_with_path in "${files[@]}"; do
file_with_path="${file_with_path// /__REPLACED__SPACE__}"
paths[index]=$(dirname "$file_with_path")

Then, unique paths are found and run terrascan for each repo folder:

# for each path run terrascan
for path_uniq in $(echo "${paths[*]}" | tr ' ' '\n' | sort -u); do

It works literally how it should work: checks only diffs.

So, good to know when the --all (-a) argument passed to pre-commit and just run terrascan -d GIT_REPO_ROOT, not all-all dirs.


Useful info

  • How to run hook performance test

  • pre-commit automatically parallel checks to exiting cores, so you need to run tests on a repo that has at least 2x more tf-dirs than CPU cores you have. If you have not so big repo - just copy-paste code-structure a few times, and you'll get needed.

  • Create solution as function, that can be called from terrascan_() hook function and depends on the result, in if run other flow and stop execution with exit 0



Founded in #305

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions