git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] checkout: optimize "git checkout -b <new_branch>"

From
Duy Nguyen <pclouds@gmail.com>
Date
Aug 1, 2018, 15:10 UTC
Message-ID
<CACsJy8DMEMsDnKZc65K-0EJcm2udXZ7OKY=xoFmX4COM0dSH=g@mail.gmail.com>
In-Reply-To
<20180731163909.19004-1-benpeart@microsoft.com>
On Tue, Jul 31, 2018 at 7:03 PM Ben Peart <Ben.Peart@microsoft.com> wrote:
Show 6 quoted lines
>
> From: Ben Peart <Ben.Peart@microsoft.com>
>
> Skip merging the commit, updating the index and working directory if and
> only if we are creating a new branch via "git checkout -b <new_branch>."
> Any other checkout options will still go through the former code path.

I'd like to see this giant list of checks broken down and pushed down to smaller areas so that chances of new things being added but checks not updated become much smaller. And ideally there should just be no behavior change (I think with your change, "checkout -b" will not report local changes, but it's not mentioned in the config document; more things like that can easily slip).

So. I assume this reason for this patch is because on super large worktrees
 - 2-way merge is too slow
 - applying spare checkout patterns on a huge worktree is also slow
 - writing index is, again, slow
 - show_local_changes() slow

For 2-way merge, I believe we can detect inside unpack_trees() that it's a 2-way merge (fn == twoway_merge), from HEAD to HEAD (simple enough check), then from the 2-way merge table we know for sure nothing is going to change and we can just skip traverse_trees() call in unpack_trees().

On the sparse checkout application. This only needs to be done when there are new files added, or the spare-checkout file has been updated since the last time it's been used. We can keep track of these things (sparse-checkout file change could be kept track with just stat info maybe as an index extension) then we can skip applying sparse checkout not for this particular case for but general checkouts as well. Spare checkout file rarely changes. Big win overall.

And if all go according to plan, there will be no changes made in the index (by either 2-way merge or sparse checkout stuff) we should be able to just skip writing down the index, if we haven't done that already.

show_local_changes() should be sped up significantly with the new cache-tree optimization I'm working on in another thread.

If I have not made any mistake in my analysis so far, we achieve a big speedup without adding a new config knob and can still fall back to slower-but-same-behavior when things are not in the right condition. I know it will not be the same speedup as this patch because when facing thousands of items, even counting them takes time. But I think it's a reasonable speedup without making the code base more fragile.

-- 
Duy
Previous: Junio C HamanoNext: Ben Peart
Message 11 of 32 in “checkout: optionally speed up "git checkout -b foo"”
  1. checkout: optionally speed up "git checkout -b foo"Ben Peart, Jul 24, 2018
  2. Eric SunshineJul 24, 2018
  3. Ben PeartJul 24, 2018
  4. Junio C HamanoJul 26, 2018
  5. Eric SunshineJul 26, 2018
  6. Eric SunshineJul 26, 2018
  7. Junio C HamanoJul 24, 2018
  8. Ben PeartJul 24, 2018
  9. checkout: optimize "git checkout -b <new_branch>"Ben Peart, Jul 31, 2018
  10. Junio C HamanoJul 31, 2018
  11. Duy NguyenAug 1, 2018
  12. Ben PeartAug 2, 2018
  13. Duy NguyenAug 3, 2018
  14. Ben PeartAug 6, 2018
  15. Ben PeartAug 15, 2018
  16. Duy NguyenAug 5, 2018
  17. checkout: optimize "git checkout -b <new_branch>"Ben Peart, Aug 16, 2018
  18. Duy NguyenAug 16, 2018
  19. Ben PeartAug 17, 2018
  20. Elijah NewrenAug 19, 2018
  21. Ben PeartAug 20, 2018
  22. Elijah NewrenAug 20, 2018
  23. Duy NguyenAug 21, 2018
  24. Elijah NewrenAug 30, 2018
  25. Duy NguyenSep 4, 2018
  26. Junio C HamanoAug 20, 2018
  27. config doc: add missing list separator for checkout.optimizeNewBranchÆvar Arnfjörð Bjarmason, Sep 18, 2018
  28. Taylor BlauSep 18, 2018
  29. Jeff KingSep 18, 2018
  30. Taylor BlauSep 18, 2018
  31. Jeff KingSep 18, 2018
  32. Ævar Arnfjörð BjarmasonSep 19, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.