Skip to content

speed up init by performing a shallow clone #47430

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

nikhedonia
Copy link
Collaborator

@nikhedonia nikhedonia commented Jul 7, 2025

Resolves: #6444

related brave-core pr: brave/brave-core#29938

@nikhedonia nikhedonia requested review from bridiver and a team as code owners July 7, 2025 17:33

// check if we want to perform a shallow clone with --no-history
// check if ref is advertised by github (ls-remote)
// If it isn't we need to perform a full clone or download an archive
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: lowercase if to be consistent with casing in comments above

@bridiver
Copy link
Contributor

bridiver commented Jul 7, 2025

This repo is deprecated, we shouldn’t be adding any new code here

@@ -0,0 +1,180 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Why would this be committed to the repo?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is probably unintentionally added?

// check if we want to perform a shallow clone with --no-history
// check if ref is advertised by github (ls-remote)
// If it isn't we need to perform a full clone or download an archive
const shouldShallowCloneBraveCore = (
Copy link
Contributor

Choose a reason for hiding this comment

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

We don’t really need to use brave-browser at all anymore and at some point we’d still like to move everything into a single repo so I don’t think we want to add anything here. Does brave-core checkout actually take a long time? I think you’re basically free to checkout brave core any way you want so no need for anything in a dedicated script. This is mostly still here for historical reasons.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree, we should have only one repo, just added this for completeness.

Does brave-core checkout actually take a long time? I think you’re basically free to checkout brave core any way you want so no need for anything in a dedicated script. This is mostly still here for historical reasons.

A full clone is 3.57Gb. But yes the brave-core can be aquired in any way as long there is a git repo with a previous commit.

At this point we just need to update docs and remove a few dependendies on the folder structure eg.: brave-core's npm run init needs to be tweaked to work in a standalone brave-core checkout as it currently runs: cd ../../ && npm run --prefix src/brave sync -- --init.

Copy link

@qwikgig-krishna qwikgig-krishna left a comment

Choose a reason for hiding this comment

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

This is a great improvement to speed up the init process! I've added a few comments with suggestions for improvement. Let me know what you think.

noHistory
&& util
.runGit('.', ['ls-remote', braveCoreUrl], false, {maxBuffer: 1024 * 1024 * 5})
.includes(braveCoreRef)

Choose a reason for hiding this comment

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

Could you add more context on why --depth=2 is needed? Specifically, which script is failing and what is the error? This would be very helpful for future developers who might need to debug this part of the code.

// check if ref is advertised by github (ls-remote)
// If it isn't we need to perform a full clone or download an archive
const shouldShallowCloneBraveCore = (
noHistory

Choose a reason for hiding this comment

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

Is the maxBuffer of 5MB an arbitrary number or is it based on the expected size of the ls-remote output? A comment explaining the reasoning behind this value would be useful.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Semi random pick. Big enough for now and for the future. I think it is suggestive that might want to reduce the amount of branches we have in brave-core...

// If it isn't we need to perform a full clone or download an archive
const shouldShallowCloneBraveCore = (
noHistory
&& util

Choose a reason for hiding this comment

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

The code doesn't seem to handle the case where ls-remote fails. If runGit returns null (which it does on failure), the subsequent call to .includes() will throw a TypeError. It would be safer to check the result of runGit for null before attempting to call .includes() on it.


if (!fs.existsSync(path.join(braveCoreDir, '.git'))) {
Log.status(`Cloning brave-core [${braveCoreRef}] into ${braveCoreDir}...`)
fs.mkdirSync(braveCoreDir)
util.runGit(braveCoreDir, ['clone', util.getNPMConfig(['projects', 'brave-core', 'repository', 'url']), '.'])

// check if we want to perform a shallow clone with --no-history

Choose a reason for hiding this comment

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

Instead of using ls-remote to check if the ref is advertised, have you considered trying a shallow clone first and then falling back to a full clone if it fails? This would avoid the overhead of ls-remote, which can be slow, and would only incur the cost of a failed git clone in the rare case where a shallow clone is not possible for the given ref.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this is a good idea. Will try

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add --no-history option to avoid checking downloading full Chromium history
4 participants