Live data from Hacker News

How we decreased GitLab repo backup times from 48 hours to 41 minutes

about.gitlab.com

261–270 of 273 posts

Re: How we decreased GitLab repo backup times from 48 hours to 41 minutes

#261

Earlier quoted context omitted.

But why couldn't they just dedupe the refs from the command line before starting the actual bundling - surely there are never more than a couple of hundred of those (one per branch)?

The point is the performance hit had nothing to do with dupe count (which could be zero), and everything to do with ref count.

Spot on. Some of our repositories at GitLab can contain millions of references.

Re: How we decreased GitLab repo backup times from 48 hours to 41 minutes

#262

Earlier quoted context omitted.

I've seen this exact problem in C code many times in my life, especially in kernel space where data structures and memory allocations are fun. Ironically, this is much _faster_ for small sets. Sometimes the error is intentional, because the programmer believes that all inputs will be small. IME, those programmers were wrong, but that's the inverse of survival bias.

And in fairness I can understand not considering someone might eventually be bundling a repository with tens of thousands of refs back in early 2009.

Even now, the contrast between repository sizes is wide. Most repos contain 1000s of references, which while not the best to run O(N^2) algorithm, is still okay. But as a Git forge, you also see a share of repositories which contain millions of references.

Re: How we decreased GitLab repo backup times from 48 hours to 41 minutes

#263

Earlier quoted context omitted.

Which term is appropriate here? What would you suggest? (honest question)

"hugely" or "a lot" or "to O(XXX)" whatever the new XXX complexity is.

"to O(xxx)" is a good idea, in terms of keeping it mathematical and accurate. I like that best. "hugely" makes me giggle, because I really hear "bigly" when I see/hear it.

Re: How we decreased GitLab repo backup times from 48 hours to 41 minutes

#264

Earlier quoted context omitted.

Depends on the constants and on the value of n . If the constant for the O(n log n) algorithm is five times that of the O(n) algorithm, the O(n) algorithm is faster for n . If you expect that n will always hold, it may be better to implement the O(n) algorithm and add a logging warning if n > 250 or so (and, maybe, a fatal error if n > 1000 or so), instead of spending time to write both versions of the algorithm and…

Fatal errors tend to blow up in production rather than test. One of the simplest solutions for detecting cyclic graphs is instead of collecting a lookup table or doing something non-concurrent like marking the nodes, is to count nodes and panic if the encountered set is more than an order of magnitude more than you expected. I came onto a project that had done that before and it blew up during my tenure. The worst ca…

Just wanted to say you're one of my favorite posters. Can't put an exact reason on why, but at some point over the last 15 years I learned to recognize your name simply from consistent high quality contributions. Cheers.

Re: How we decreased GitLab repo backup times from 48 hours to 41 minutes

#265
post #134

Earlier quoted context omitted.

The algorithm complexity went down in the function they patched (6x improvement in their benchmark), but in the context of how they benefited with how they were using the algorithm the impact was much larger (improved to taking 1% of the time), which is plausibly exponential (and figuring out the actual complexity is neither relevant nor an economic use of time).

> figuring out the actual complexity is neither relevant nor an economic use of time The fix was replacing a nested loop with a map. Figuring out that this goes from O(n^2) to O(n) (modulo details like bucket count) is immediate if you know what the words mean and understand enough to identify the problem and make the fix in the first place.

Yes that's the algorithmic complexity of the function they patched.

Re: How we decreased GitLab repo backup times from 48 hours to 41 minutes

#266

Earlier quoted context omitted.

They’re too ridiculous… unless a more optimal solution does not exist

Absolutely not. If the cost of doing something goes above quadratic, you shouldn't do it at all. Because essentially every customer interaction costs you more than the one before. You will never be able to come up with ways to cover that cost faster than it ramps. You are digging a hole, filling it with cash and lighting it on fire. If you can't do something well you should consider not doing it at all. If you can on…

Not all n's grow unbounded with the number of customers. If anything, having a reasonable upper bound for how high a n you have to support is the more common case - and you're going to need that with O(n) as well.

Re: How we decreased GitLab repo backup times from 48 hours to 41 minutes

#267

Earlier quoted context omitted.

> That is not the case in C though, as it is much easier to use arrays and nested loops instead of hash maps. I am confused. There are plenty of open source, fast hash map impls in C.

Yes, the problem is getting them into your project.

That's only a problem if you have never done any C development.

Re: How we decreased GitLab repo backup times from 48 hours to 41 minutes

#268

Earlier quoted context omitted.

Meaningless and non-constructive pedantry.

>pedantry I wasted 2 minutes of my life looking for the exponential reduction. So did many others. Now I'm wasting more of my life shit posting about it, but at least that's a conscious choice.

No, you spent 2 minutes improving your reading comprehension.

Re: How we decreased GitLab repo backup times from 48 hours to 41 minutes

#269
post #39

A very good example that writing code in C doesn't help for performance, when the algorithms or data structures aren't properly taken into consideration.

C does help with the C that is often conveniently omitted in the big O notation. That matters just as much as the algorithmic complexity - both need to be reasonable or the software will be slow. No one ever claimed C affects algorithmic complexity.

Re: How we decreased GitLab repo backup times from 48 hours to 41 minutes

#270
post #29
post #26

Here comes an unpopular nitpick: "... we traced the issue to a 15-year-old Git function with O(N²) complexity and fixed it with an algorithmic change, reducing backup times exponentially." Uh no you didn't. Not possible. At most a polynomial reduction is possible else complexity theory needs a re-write. (OK, yes, k could be doing some heavy lifting here, but I doubt it.) If you are going to quote a maths formula then…

OP here. Feedback is always welcome, I did mean exponentially in the colloquial sense. I do see how it is confusing here, will change it.

I'm disappointed that the page has not been fixed...
Post reply on HN