Skip to content

Commit

Permalink
gitimport: Make bookmark generation >10x faster for already imported …
Browse files Browse the repository at this point in the history
…tags

Summary:
I noticed when re-importing `whatsapp/voip` (which has ~2k tags) that even though most tags were already imported,
it took multiple seconds to iterate over each one with `generate-bookmark`.

Looking at the code, we used to upload the git tag objects every time, even if the tag
already existed.
That's at least two blobstore puts, which explains the  delay.

After this change, the speed is closer to ~5-10 tags per second, as expected.

We could still optimize further by parallelizing the bookmark generation, but this diff
only fixes an obvious pessimization.

Reviewed By: YousefSalama

Differential Revision: D54684266

fbshipit-source-id: 5cddcbc7164a84f81fba184e0d83f6226d41a035
  • Loading branch information
Pierre Chevalier authored and facebook-github-bot committed May 3, 2024
1 parent 93c70b5 commit c9d1f9e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
25 changes: 16 additions & 9 deletions eden/mononoke/git/gitimport/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* GNU General Public License version 2.
*/

#![feature(async_closure)]

mod mem_writes_changesets;
use std::collections::HashMap;
use std::path::Path;
Expand Down Expand Up @@ -368,15 +370,18 @@ async fn async_main(app: MononokeApp) -> Result<(), Error> {
// Skip the HEAD revision: it shouldn't be imported as a bookmark in mononoke
continue;
}
if let Some(tag_id) = maybe_tag_id {
// The ref getting imported is a tag, so store the raw git Tag object.
upload_git_tag(&ctx, &uploader, path, &prefs, tag_id).await?;
// Create the changeset corresponding to the commit pointed to by the tag.
create_changeset_for_annotated_tag(
&ctx, &uploader, path, &prefs, tag_id, changeset,
)
.await?;
}
let upload_if_tag = async {
if let Some(tag_id) = maybe_tag_id {
// The ref getting imported is a tag, so store the raw git Tag object.
upload_git_tag(&ctx, &uploader, path, &prefs, tag_id).await?;
// Create the changeset corresponding to the commit pointed to by the tag.
create_changeset_for_annotated_tag(
&ctx, &uploader, path, &prefs, tag_id, changeset,
)
.await?;
}
Ok::<_, Error>(())
};
let bookmark_key = BookmarkKey::new(&name)?;

let pushvars = if args.bypass_readonly {
Expand All @@ -396,6 +401,7 @@ async fn async_main(app: MononokeApp) -> Result<(), Error> {
// The bookmark already exists. Instead of creating it, we need to move it.
Some(old_changeset) => {
if old_changeset != final_changeset {
upload_if_tag.await?;
let allow_non_fast_forward = true;
repo_context
.move_bookmark(
Expand All @@ -420,6 +426,7 @@ async fn async_main(app: MononokeApp) -> Result<(), Error> {
}
// The bookmark doesn't yet exist. Create it.
None => {
upload_if_tag.await?;
repo_context
.create_bookmark(&bookmark_key, final_changeset, pushvars.as_ref())
.await
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,3 @@
$ rm -rf git_client_repo
$ git clone "$BUNDLE_PATH" git_client_repo
Cloning into 'git_client_repo'...
fatal: bad object 8963e1f55d1346a07c3aec8c8fc72bf87d0452b1
fatal: remote did not send all necessary objects
[128]

0 comments on commit c9d1f9e

Please sign in to comment.