Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We have a shell script that invokes `chef install` and `chef export` against a setup with ~30 cookbooks. It was annoyingly slow so we dug into why that was the case. We found that these commands call `ChefCLI::CookbookProfiler::Git` in a loop which ends up shelling out the same handful of git commands repeatedly. For example, one run produced the following duplicate git commands (sorted by dupe count): ``` 74 execve("/usr/bin/git", ["git", "rev-parse", "HEAD"], 46 execve("/usr/bin/git", ["git", "rev-parse", "HEAD"], 41 execve("/usr/bin/git", ["git", "rev-parse", "--abbrev-ref", "HEAD"], 39 execve("/usr/bin/git", ["git", "diff-files", "--quiet"], 25 execve("/usr/bin/git", ["git", "branch", "-r", "--contains", "<snip>"], 23 execve("/usr/lib/git-core/git", ["/usr/lib/git-core/git", "status", "--porcelain=2", "-uno"], 23 execve("/usr/bin/git", ["git", "config", "--get", "branch.HEAD.remote"], 21 execve("/usr/bin/git", ["git", "diff-files", "--quiet"], 19 execve("/usr/bin/git", ["git", "rev-parse", "--abbrev-ref", "HEAD"], 17 execve("/usr/bin/git", ["git", "config", "--get", "branch.<snip>.remote"], 16 execve("/usr/bin/git", ["git", "config", "--get", "remote.origin.url"], 14 execve("/usr/bin/git", ["git", "branch", "-r", "--contains", "<snip>"], 14 execve("/usr/bin/git", ["git", "branch", "-r", "--contains", "<snip>"], 12 execve("/usr/bin/git", ["git", "config", "--get", "remote.origin.url"], 11 execve("/usr/bin/git", ["git", "config", "--get", "branch.<snip>.remote"], 9 execve("/usr/bin/git", ["git", "config", "--get", "branch.HEAD.remote"], 7 execve("/usr/bin/git", ["git", "branch", "-r", "--contains", "<snip>"], 5 execve("/usr/lib/git-core/git", ["/usr/lib/git-core/git", "status", "--porcelain=2", "-uno"], ``` Adding a simple memoization brought down our run from ~45s to ~1s. To be a little safer, we could wrap this is a `git_memo` method to make it more explicit. I thought I'd collect some initial feedback on the general idea first. Signed-off-by: Adam Saponara <as@php.net>
- Loading branch information