Skip to content

gix for diff tree hunks #5899

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 8, 2025
Merged

gix for diff tree hunks #5899

merged 1 commit into from
Jan 8, 2025

Conversation

Byron
Copy link
Collaborator

@Byron Byron commented Jan 8, 2025

The is to speed up apply_branch() which currently takes about 5m even with an uptodate workspace and a single virtual branch with a single commit and a single file changed inside of that.

Compared to the last time I checked, it seems the tree-diff portion is just 10% of the time, while BranchOwnershipClaim::put() takes the rest of it. All of this is part of the undo_commit() function which is probably related to the WIP commit being undone.

Screenshot 2025-01-08 at 11 33 55

Tasks

  • profile to figure out what to focus on
  • make the issue reproducible with the CLI
  • optimize undo_commit() - this portion is going to be gone, entirely

Additional Issues

  • WIP-Commit creation causes the signing machinery to run. This is more likely to fail and isn't necessary.
    • If the commit-creation fails the UI seems to go into a very invalid state.
  • Branches with WIP commit seem to easily get 'UUID'-branch names Screenshot 2025-01-08 at 13 01 24
  • Branch Duplication - and what also happens is that it somehow considers a lot of changed files/lines
duplicate-branch.mov

Research

Before

In GitLab@82895d0a33f4687886c6d36f7fcb6db1f20b522e,

❯ gitbutler-cli -d branch apply -b c1544bac-7804-482e-b75d-705f53a1a61e
some branches already selected for changes
c1544bac-7804-482e-b75d-705f53a1a61e
INFO     cli-op [ 302s | 0.05% / 100.00% ]
INFO     ┝━ ThreadSafeRepository::discover() [ 828µs | 0.00% / 0.00% ]
INFO     │  ┕━ open_from_paths() [ 629µs | 0.00% / 0.00% ]
INFO     │     ┕━ gix_odb::Store::at() [ 234µs | 0.00% ]
INFO     ┝━ create_snapshot [ 69.7ms | 0.02% / 0.02% ]
INFO     │  ┕━ ThreadSafeRepository::open() [ 190µs | 0.00% / 0.00% ]
INFO     │     ┕━ open_from_paths() [ 160µs | 0.00% / 0.00% ]
INFO     │        ┕━ gix_odb::Store::at() [ 88.5µs | 0.00% ]
DEBUG    ┕━ apply_branch [ 302s | 99.32% / 99.92% ] stack_id: c1544bac-7804-482e-b75d-705f53a1a61e
DEBUG       ┝━ create_wd_tree [ 479ms | 0.16% / 0.16% ]
INFO        │  ┝━ ThreadSafeRepository::open() [ 298µs | 0.00% / 0.00% ]
INFO        │  │  ┕━ open_from_paths() [ 263µs | 0.00% / 0.00% ]
INFO        │  │     ┕━ gix_odb::Store::at() [ 139µs | 0.00% ]
INFO        │  ┕━ gix_index::File::at() [ 6.97ms | 0.00% ]
INFO        ┝━ ThreadSafeRepository::open() [ 246µs | 0.00% / 0.00% ]
INFO        │  ┕━ open_from_paths() [ 208µs | 0.00% / 0.00% ]
INFO        │     ┕━ gix_odb::Store::at() [ 107µs | 0.00% ]
INFO        ┝━ gix_index::File::at() [ 7.33ms | 0.00% ]
INFO        ┝━ gix_merge::tree [ 3.40ms | 0.00% ] base_tree: Sha1(f6d74d3680512d925d0d1a0f1121d2d92d07e8c1) | our_tree: Sha1(f6d74d3680512d925d0d1a0f1121d2d92d07e8c1) | their_tree: Sha1(f6d74d3680512d925d0d1a0f1121d2d92d07e8c1) | labels: Labels { ancestor: None, current: None, other: None }
DEBUG       ┝━ update_workspace_commit [ 401ms | 0.08% / 0.13% ]
DEBUG       │  ┕━ get_workspace_head [ 147ms | 0.04% / 0.05% ]
INFO        │     ┝━ ThreadSafeRepository::open() [ 1.35ms | 0.00% / 0.00% ]
INFO        │     │  ┕━ open_from_paths() [ 1.28ms | 0.00% / 0.00% ]
INFO        │     │     ┕━ gix_odb::Store::at() [ 155µs | 0.00% ]
INFO        │     ┝━ gix_index::File::at() [ 9.09ms | 0.00% ]
INFO        │     ┕━ gix_merge::tree [ 3.45ms | 0.00% ] base_tree: Sha1(f6d74d3680512d925d0d1a0f1121d2d92d07e8c1) | our_tree: Sha1(f6d74d3680512d925d0d1a0f1121d2d92d07e8c1) | their_tree: Sha1(f6d74d3680512d925d0d1a0f1121d2d92d07e8c1) | labels: Labels { ancestor: Some("base"), current: Some("ours"), other: Some("theirs") }
DEBUG       ┝━ checkout_branch_trees [ 550ms | 0.18% ]
DEBUG       ┕━ update_workspace_commit [ 389ms | 0.08% / 0.13% ]
DEBUG          ┕━ get_workspace_head [ 141ms | 0.04% / 0.05% ]
INFO              ┝━ ThreadSafeRepository::open() [ 409µs | 0.00% / 0.00% ]
INFO              │  ┕━ open_from_paths() [ 331µs | 0.00% / 0.00% ]
INFO              │     ┕━ gix_odb::Store::at() [ 172µs | 0.00% ]
INFO              ┝━ gix_index::File::at() [ 6.86ms | 0.00% ]
INFO              ┕━ gix_merge::tree [ 3.41ms | 0.00% ] base_tree: Sha1(f6d74d3680512d925d0d1a0f1121d2d92d07e8c1) | our_tree: Sha1(f6d74d3680512d925d0d1a0f1121d2d92d07e8c1) | their_tree: Sha1(f6d74d3680512d925d0d1a0f1121d2d92d07e8c1) | labels: Labels { ancestor: Some("base"), current: Some("ours"), other: Some("theirs") }
With added debugging
❯ /Users/byron/dev/github.com/gitbutlerapp/gitbutler/target/release/gitbutler-cli -d -C gitlab branch apply -b c1544bac-7804-482e-b75d-705f53a1a61e
some branches already selected for changes
c1544bac-7804-482e-b75d-705f53a1a61e
INFO     cli-op [ 297s | 0.06% / 100.00% ]
INFO     ┝━ ThreadSafeRepository::discover() [ 1.74ms | 0.00% / 0.00% ]
INFO     │  ┕━ open_from_paths() [ 1.32ms | 0.00% / 0.00% ]
INFO     │     ┕━ gix_odb::Store::at() [ 420µs | 0.00% ]
INFO     ┝━ create_snapshot [ 84.3ms | 0.03% / 0.03% ]
INFO     │  ┕━ ThreadSafeRepository::open() [ 244µs | 0.00% / 0.00% ]
INFO     │     ┕━ open_from_paths() [ 213µs | 0.00% / 0.00% ]
INFO     │        ┕━ gix_odb::Store::at() [ 124µs | 0.00% ]
DEBUG    ┕━ apply_branch [ 296s | 0.05% / 99.91% ] stack_id: c1544bac-7804-482e-b75d-705f53a1a61e
DEBUG       ┝━ create_wd_tree [ 842ms | 0.28% / 0.28% ]
INFO        │  ┝━ ThreadSafeRepository::open() [ 297µs | 0.00% / 0.00% ]
INFO        │  │  ┕━ open_from_paths() [ 257µs | 0.00% / 0.00% ]
INFO        │  │     ┕━ gix_odb::Store::at() [ 145µs | 0.00% ]
INFO        │  ┕━ gix_index::File::at() [ 7.54ms | 0.00% ]
INFO        ┝━ ThreadSafeRepository::open() [ 307µs | 0.00% / 0.00% ]
INFO        │  ┕━ open_from_paths() [ 270µs | 0.00% / 0.00% ]
INFO        │     ┕━ gix_odb::Store::at() [ 137µs | 0.00% ]
INFO        ┝━ gix_index::File::at() [ 7.33ms | 0.00% ]
INFO        ┝━ gix_merge::tree [ 3.27ms | 0.00% ] base_tree: Sha1(f6d74d3680512d925d0d1a0f1121d2d92d07e8c1) | our_tree: Sha1(f6d74d3680512d925d0d1a0f1121d2d92d07e8c1) | their_tree: Sha1(f6d74d3680512d925d0d1a0f1121d2d92d07e8c1) | labels: Labels { ancestor: None, current: None, other: None }
DEBUG       ┝━ undo_commit [ 294s | 88.92% / 99.24% ] stack_id: c1544bac-7804-482e-b75d-705f53a1a61e | commit_to_remove: d05652ad7cc1edb932ba8ad4e189b0f9c13f3d62
DEBUG       │  ┝━ rebase_all_but_last [ 30.2s | 10.18% ] branch_head_commit: d05652ad7cc1edb932ba8ad4e189b0f9c13f3d62 | commit_to_remove: d05652ad7cc1edb932ba8ad4e189b0f9c13f3d62
DEBUG       │  ┕━ update_workspace_commit [ 403ms | 0.09% / 0.14% ]
DEBUG       │     ┕━ get_workspace_head [ 148ms | 0.04% / 0.05% ]
INFO        │        ┝━ ThreadSafeRepository::open() [ 1.54ms | 0.00% / 0.00% ]
INFO        │        │  ┕━ open_from_paths() [ 1.47ms | 0.00% / 0.00% ]
INFO        │        │     ┕━ gix_odb::Store::at() [ 206µs | 0.00% ]
INFO        │        ┝━ gix_index::File::at() [ 9.81ms | 0.00% ]
INFO        │        ┕━ gix_merge::tree [ 3.62ms | 0.00% ] base_tree: Sha1(f6d74d3680512d925d0d1a0f1121d2d92d07e8c1) | our_tree: Sha1(f6d74d3680512d925d0d1a0f1121d2d92d07e8c1) | their_tree: Sha1(f6d74d3680512d925d0d1a0f1121d2d92d07e8c1) | labels: Labels { ancestor: Some("base"), current: Some("ours"), other: Some("theirs") }
DEBUG       ┝━ checkout_branch_trees [ 601ms | 0.20% ]
DEBUG       ┕━ update_workspace_commit [ 397ms | 0.08% / 0.13% ]
DEBUG          ┕━ get_workspace_head [ 149ms | 0.05% / 0.05% ]
INFO              ┝━ ThreadSafeRepository::open() [ 432µs | 0.00% / 0.00% ]
INFO              │  ┕━ open_from_paths() [ 332µs | 0.00% / 0.00% ]
INFO              │     ┕━ gix_odb::Store::at() [ 175µs | 0.00% ]
INFO              ┝━ gix_index::File::at() [ 7.26ms | 0.00% ]
INFO              ┕━ gix_merge::tree [ 3.34ms | 0.00% ] base_tree: Sha1(f6d74d3680512d925d0d1a0f1121d2d92d07e8c1) | our_tree: Sha1(f6d74d3680512d925d0d1a0f1121d2d92d07e8c1) | their_tree: Sha1(f6d74d3680512d925d0d1a0f1121d2d92d07e8c1) | labels: Labels { ancestor: Some("base"), current: Some("ours"), other: Some("theirs") }
[crates/gitbutler-branch-actions/src/undo_commit.rs:40:5] &ownership_update.len() = 76936
[crates/gitbutler-branch-actions/src/undo_commit.rs:40:5] stack.ownership.claims.len() = 7010

Copy link

vercel bot commented Jan 8, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
gitbutler-components ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 8, 2025 3:02pm
gitbutler-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 8, 2025 3:02pm

@vercel vercel bot temporarily deployed to Preview – gitbutler-components January 8, 2025 10:32 Inactive
@vercel vercel bot temporarily deployed to Preview – gitbutler-web January 8, 2025 10:32 Inactive
@Byron Byron mentioned this pull request Jan 8, 2025
8 tasks
@Byron Byron force-pushed the gix-diff-tree-hunks branch from 2b9a12b to 1ecb346 Compare January 8, 2025 14:44
@github-actions github-actions bot added the rust Pull requests that update Rust code label Jan 8, 2025
@Byron Byron marked this pull request as ready for review January 8, 2025 14:44
Comment on lines 59 to 61

fn inner_undo_commit(
#[instrument(level = tracing::Level::DEBUG, skip(repository))]
fn rebase_all_but_last(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would rebase_excluding be a better name?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's actually what it's doing. Renaming it.

@Byron Byron force-pushed the gix-diff-tree-hunks branch from 1ecb346 to 5db8ef8 Compare January 8, 2025 14:59
@Byron Byron enabled auto-merge January 8, 2025 14:59
@Byron Byron merged commit 1c264f1 into master Jan 8, 2025
21 checks passed
@Byron Byron deleted the gix-diff-tree-hunks branch January 8, 2025 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants