Skip to content

Commit 13deabd

Browse files
committed
find large files more quickly thanks to gix based dirwalk
Also make sure that important `gix` crates are always compiled with optimization for proper performance. This is particularly useful when optimizing performance as not everything has to be done in release mode. However, it also causes CI to be slower as it compiles some dependencies longer. The problem realy is that `tauri dev` doesn't support custom profiles, so there is only `dev` and `release`.
1 parent 7ce1439 commit 13deabd

File tree

2 files changed

+40
-16
lines changed

2 files changed

+40
-16
lines changed

DEVELOPMENT.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,23 @@ One can get performance log when launching the application locally as follows:
138138
GITBUTLER_PERFORMANCE_LOG=1 LOG_LEVEL=debug pnpm tauri dev
139139
```
140140

141+
For more realistic performance logging, use local release builds with `--release`.
142+
143+
```bash
144+
GITBUTLER_PERFORMANCE_LOG=1 LOG_LEVEL=debug pnpm tauri dev --release
145+
```
146+
147+
Since release builds are configured for public releases, they are very slow to compile.
148+
Speed them up by sourcing the following file.
149+
150+
```bash
151+
export CARGO_PROFILE_RELEASE_DEBUG=0
152+
export CARGO_PROFILE_RELEASE_INCREMENTAL=false
153+
export CARGO_PROFILE_RELEASE_LTO=false
154+
export CARGO_PROFILE_RELEASE_CODEGEN_UNITS=256
155+
export CARGO_PROFILE_RELEASE_OPT_LEVEL=2
156+
```
157+
141158
### Tokio
142159

143160
We are also collecting tokio's runtime tracing information that could be viewed using [tokio-console](https://github.com/tokio-rs/console#tokio-console-prototypes):

crates/gitbutler-oplog/src/oplog.rs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use gitbutler_project::{
1515
Project,
1616
};
1717
use gitbutler_repo::RepositoryExt;
18+
use gix::bstr::{BString, ByteSlice, ByteVec};
1819
use tracing::instrument;
1920

2021
use super::{
@@ -717,22 +718,28 @@ fn worktree_files_larger_than_limit_as_git2_ignore_rule(
717718
repo: &git2::Repository,
718719
worktree_dir: &Path,
719720
) -> Result<String> {
720-
let statuses = repo.statuses(None)?;
721-
let mut files_to_exclude = vec![];
722-
for entry in statuses.iter() {
723-
let Some(rela_path) = entry.path() else {
724-
continue;
725-
};
726-
let full_path = worktree_dir.join(rela_path);
727-
if let Ok(metadata) = fs::metadata(&full_path) {
728-
if metadata.is_file()
729-
&& metadata.len() > SNAPSHOT_FILE_LIMIT_BYTES
730-
&& entry.status().is_wt_new()
731-
{
732-
files_to_exclude.push(rela_path.to_owned());
733-
}
734-
}
735-
}
721+
let repo = gix::open(repo.path())?;
722+
let files_to_exclude: Vec<_> = repo
723+
.dirwalk_iter(
724+
repo.index_or_empty()?,
725+
None::<BString>,
726+
Default::default(),
727+
repo.dirwalk_options()?
728+
.emit_ignored(None)
729+
.emit_pruned(false)
730+
.emit_untracked(gix::dir::walk::EmissionMode::Matching),
731+
)?
732+
.filter_map(Result::ok)
733+
.filter_map(|item| {
734+
let path = worktree_dir.join(gix::path::from_bstr(item.entry.rela_path.as_bstr()));
735+
let file_is_too_large = path.metadata().map_or(false, |md| {
736+
md.is_file() && md.len() > SNAPSHOT_FILE_LIMIT_BYTES
737+
});
738+
file_is_too_large
739+
.then(|| Vec::from(item.entry.rela_path).into_string().ok())
740+
.flatten()
741+
})
742+
.collect();
736743
Ok(files_to_exclude.join(" "))
737744
}
738745

0 commit comments

Comments
 (0)