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`.
This commit is contained in:
Sebastian Thiel 2024-08-28 15:33:37 +02:00
parent 7ce143954f
commit 13deabdebd
No known key found for this signature in database
GPG Key ID: 9CB5EE7895E8268B
2 changed files with 40 additions and 16 deletions

View File

@ -138,6 +138,23 @@ One can get performance log when launching the application locally as follows:
GITBUTLER_PERFORMANCE_LOG=1 LOG_LEVEL=debug pnpm tauri dev
```
For more realistic performance logging, use local release builds with `--release`.
```bash
GITBUTLER_PERFORMANCE_LOG=1 LOG_LEVEL=debug pnpm tauri dev --release
```
Since release builds are configured for public releases, they are very slow to compile.
Speed them up by sourcing the following file.
```bash
export CARGO_PROFILE_RELEASE_DEBUG=0
export CARGO_PROFILE_RELEASE_INCREMENTAL=false
export CARGO_PROFILE_RELEASE_LTO=false
export CARGO_PROFILE_RELEASE_CODEGEN_UNITS=256
export CARGO_PROFILE_RELEASE_OPT_LEVEL=2
```
### Tokio
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):

View File

@ -15,6 +15,7 @@ use gitbutler_project::{
Project,
};
use gitbutler_repo::RepositoryExt;
use gix::bstr::{BString, ByteSlice, ByteVec};
use tracing::instrument;
use super::{
@ -717,22 +718,28 @@ fn worktree_files_larger_than_limit_as_git2_ignore_rule(
repo: &git2::Repository,
worktree_dir: &Path,
) -> Result<String> {
let statuses = repo.statuses(None)?;
let mut files_to_exclude = vec![];
for entry in statuses.iter() {
let Some(rela_path) = entry.path() else {
continue;
};
let full_path = worktree_dir.join(rela_path);
if let Ok(metadata) = fs::metadata(&full_path) {
if metadata.is_file()
&& metadata.len() > SNAPSHOT_FILE_LIMIT_BYTES
&& entry.status().is_wt_new()
{
files_to_exclude.push(rela_path.to_owned());
}
}
}
let repo = gix::open(repo.path())?;
let files_to_exclude: Vec<_> = repo
.dirwalk_iter(
repo.index_or_empty()?,
None::<BString>,
Default::default(),
repo.dirwalk_options()?
.emit_ignored(None)
.emit_pruned(false)
.emit_untracked(gix::dir::walk::EmissionMode::Matching),
)?
.filter_map(Result::ok)
.filter_map(|item| {
let path = worktree_dir.join(gix::path::from_bstr(item.entry.rela_path.as_bstr()));
let file_is_too_large = path.metadata().map_or(false, |md| {
md.is_file() && md.len() > SNAPSHOT_FILE_LIMIT_BYTES
});
file_is_too_large
.then(|| Vec::from(item.entry.rela_path).into_string().ok())
.flatten()
})
.collect();
Ok(files_to_exclude.join(" "))
}