Skip to content

Commit

Permalink
perf(changelog): cache commit retain checks (258 times faster generat…
Browse files Browse the repository at this point in the history
…ion) (#772)

* perf: cache commit retain checks + 87 times faster generation

This caches the commit retain checks whenever include/exclude paths are specified.

This speeds up changelog generation by `87` times in a big repository I have:
```
Now: 0.237 s
Before:  20.633 s
```

* perf: use separate retain_commit cache for each repository

* fix: use cacache for parallel git-local cache - 258 times faster

Sled fails to open the cache if multiple git-cliff processes run on the same repository. This fixes the issue by using cacache which stores the cache locally under .git/git-cliff

* fix: cache changed files of a commit directly

This slows down the retain_commit check by ~2 times, but allows reusing the cache in case the include/exclude patterns change.
This is beneficial for running in monorepos where git-cliff runs multiple times to generate changelog for different subsets of the repo

* fix: consider include/exclude patterns together

* fix: handle first commit for changed_files

* fix: normalize glob patterns to ignore ./

* docs: add docs for retain_commit_check and cache algorithms

* fix: add ** if a pattern represents a directory

* test: add tests for should retain commit checks

* fix: correctly get the files list for the first commit

* test: add test email/name for git commits

* fix: use / for path joining in entries to match the git behaviour

* fix: revert change of include/exclude patterns to slices

The slices are normalized, so an owned pattern is needed to avoid type mismatch between new normalized/unchanged patterns

* refactor: polish implementation

* refactor: apply clippy suggestion

---------

Co-authored-by: Orhun Parmaksız <[email protected]>
  • Loading branch information
aminya and orhun authored Aug 6, 2024
1 parent 2471745 commit 8430c5c
Show file tree
Hide file tree
Showing 4 changed files with 420 additions and 34 deletions.
36 changes: 35 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions git-cliff-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ lazy_static.workspace = true
thiserror = "1.0.61"
serde = { version = "1.0.203", features = ["derive"] }
serde_json = "1.0.118"
bincode = "2.0.0-rc.3"
serde_regex = "1.1.0"
tera = "1.20.0"
indexmap = { version = "2.2.6", optional = true }
Expand All @@ -75,6 +76,7 @@ futures = { version = "0.3.30", optional = true }
url = "2.5.2"
dyn-clone = "1.0.17"
urlencoding = "2.1.3"
cacache = { version = "13.0.0", features = ["mmap"], default-features = false }

[dependencies.git2]
version = "0.19.0"
Expand All @@ -97,6 +99,7 @@ features = ["debug-embed", "compression"]
[dev-dependencies]
pretty_assertions = "1.4.0"
expect-test = "1.5.0"
temp-dir = "0.1.13"

[package.metadata.docs.rs]
all-features = true
Expand Down
Loading

0 comments on commit 8430c5c

Please sign in to comment.