News for hackers. Stuff that matters.
Re:Shrunked JavaScript monorepo Git size by 94% by eviks on Sunday October 27, 2024 @02:30AM (#41960295)
upd: silly mistake - file name does not include its full path

The explanation probably got lost among all the gifs, but the last 16 chars here are different:

> was actually only checking the last 16 characters of a filename > For example, if you changed repo/packages/foo/CHANGELOG.md, when git was getting ready to do the push, it was generating a diff against repo/packages/bar/CHANGELOG.md!

Re:Shrunked JavaScript monorepo Git size by 94% by tux3 on Sunday October 27, 2024 @03:58AM (#41960636)
Derrick provides a better explanation in this cover letter: https://lore.kernel.org/git/pull.1785.git.1725890210.gitgitg...

(See also the path-walk API cover letter: https://lore.kernel.org/all/pull.1786.git.1725935335.gitgitg...)

The example in the blog post isn't super clear, but Git was essentially taking all the versions of all the files in the repo, putting the last 16 bytes of the path (not filename) in a hash table, and using that to group what they expected to be different versions of the same file together for delta compression.

Indeed in the blog it doesn't work, because foo/CHANGELOG.md and bar/CHANGELOG.md is only 13 chars, but you have to imagine the paths have a longer common suffix. That part is fixed by the --full-name-hash option, now you compare the full path instead of just 16 bytes.

Then they talk about increasing the window size. That's kind of a hack to workaround bad file grouping, but it's not the real fix. You're still giving terrible inputs to the compressor and working around it by consuming huge amounts of memory. So that was a bit confusing to present it as the solution. The path walk API and/or --full-name-hash are the real interesting parts here =)

Re:Shrunked JavaScript monorepo Git size by 94% by lastdong on Sunday October 27, 2024 @04:16AM (#41960730)
Thank you! I ended up having to look at the PR to make any sense of the blog post.
Re:Shrunked JavaScript monorepo Git size by 94% by jonathancreamer on Monday October 28, 2024 @05:09PM (#41976320)
I'll update the post with this clarity too. Thanks!
Re:Shrunked JavaScript monorepo Git size by 94% by derriz on Sunday October 27, 2024 @03:16AM (#41960457)
I wish they had provided an actual explanation of what exactly was happening and skipped all the “color” in the story. By filename do they mean path? Or is it that git will just pick any file with a matching name to generate a diff? Is there any pattern to the choice of other file to use?
Re:Shrunked JavaScript monorepo Git size by 94% by snthpy on Sunday October 27, 2024 @03:47AM (#41960576)
+1
Re:Shrunked JavaScript monorepo Git size by 94% by p4bl0 on Sunday October 27, 2024 @03:24AM (#41960487)
I was also bugged by that. I imagine that the meta variables foo and bar are at fault here, and that probably the actual package names had a common suffix like firstPkg and secondPkg. A common suffix of length three is enough in this case to get 16 chars in common as "/CHANGELOG.md" is already 13 chars long.
Re:Shrunked JavaScript monorepo Git size by 94% by daenney on Sunday October 27, 2024 @03:36AM (#41960531)
File name doesn’t necessarily include the whole path. The last 16 characters of CHANGELOG.md is the full file name.

If we interpret it that way, that also explains why the filepathwalk solution solves the problem.

But if it’s really based on the last 16 characters of just the file name, not the whole path, then it feels like this problem should be a lot more common. At least in monorepos.

Re:Shrunked JavaScript monorepo Git size by 94% by eviks on Sunday October 27, 2024 @04:19AM (#41960747)
yes, this makes sense, thanks for pointing it out, silly confusion on my part
Re:Shrunked JavaScript monorepo Git size by 94% by floam on Sunday October 27, 2024 @03:55AM (#41960622)
It did shrink Chromium’s repo quite a bit!
Re:Shrunked JavaScript monorepo Git size by 94% by js2 on Sunday October 27, 2024 @04:03PM (#41965217)
> file name does not include its full path

No, it is the full path that's considered. Look at the commit message on the first commit in the `--full-name-hash` PR:

https://github.com/git-for-windows/git/pull/5157/commits/d5c...

Excerpt: "/CHANGELOG.json" is 15 characters, and is created by the beachball [1] tool. Only the final character of the parent directory can differntiate different versions of this file, but also only the two most-significant digits. If that character is a letter, then this is always a collision. Similar issues occur with the similar "/CHANGELOG.md" path, though there is more opportunity for differences in the parent directory.

Re:Shrunked JavaScript monorepo Git size by 94% by eviks on Monday October 28, 2024 @01:56AM (#41968160)
Thanks for the deep dive!
Re:Shrunked JavaScript monorepo Git size by 94% by rurban on Monday October 28, 2024 @03:46PM (#41975343)
Sounds like it needs to be fixed to FNV1a
Re:Shrunked JavaScript monorepo Git size by 94% by js2 on Tuesday October 29, 2024 @12:59PM (#41986557)
No, the problem isn't the hash. It does what it was designed to do. It's just that it was optimal for a particular use case that fits the Linux kernel better than Microsoft's use case. Switching the hash wouldn't improve either situation. If you want to understand this deeper, see the linked PRs.
Re:Shrunked JavaScript monorepo Git size by 94% by jonathancreamer on Monday October 28, 2024 @05:18PM (#41976414)
Sorry about the gifs. Haha. And yeah I guess my understanding wasn't quite right either reading the reply to this thread, I'll try to clean it up in the post.