3 ms·
> The thing about Computer Science nowadays is that the machines are stupidly fast so that a lot of the algorithm stuff is redundant. Accidentally quadratic is
by deathanatos 4y ago
> The thing about Computer Science nowadays is that the machines are stupidly fast so that a lot of the algorithm stuff is redundant.
Accidentally quadratic is such a thing there's a blog[1], and it's regularly the source of problems of a certain blogger who debugs problems in Windows that are usually causing his "stupidly fast" hardware to run bog slow[2].
Just this week, I hit what seems to be an accidentally-quadratic bug in macOS's tail — tail! I'm not even sure how you write an accidental O(n²) in implementing tail, but yet macOS tail takes 7 minutes to process a log file on my system that GNU tail can process in 80 milliseconds.
Regex regularly lead to oops-O(n²) due to devs not grokking the greedy nature of the star character, and for a while last year it felt like every week some NPM package was getting a security vuln. for a DoS vuln. due to quadratic regexes.
Understanding how B-Trees work — and more importantly, when they don't — in database queries is a perennial source of bugs in every company I've worked at where queries get written that won't hit an index, and don't get noticed until they're hitting production levels of rows. Dev confusion entails — "but the index has the columns I'm querying!" … yes, but that's not how a B-Tree works.
And it's not just the order-notation. I've seen, numerous times, people re-discover topological sort, or worse, hack a solution onto a problem where the problem is a DAG, and the solution is topo-sort, but instead you get something that isn't topo-sort, and just performs worse. Gitlab's CI failed to model CI jobs as a DAG[3], and as a result, will not launch jobs in some cases that can be run when they can be run.
> Sprints
Yeah, these destroy dev's souls.
[1]: https://accidentallyquadratic.tumblr.com/ https://accidentallyquadratic.tumblr.com/
[2]: https://randomascii.wordpress.com/ https://randomascii.wordpress.com/
[3]: I hear it has been fixed, but I've since left it so I've not had an opportunity. Regardless, the point is that the solution was obvious … if you know the theory. Or even contemporaries, like Make.
- stormbrew 4y ago> Just this week, I hit what seems to be an accidentally-quadratic bug in macOS's tail — tail! I'm not even sure how you write an accidental O(n²) in implementing tail, but yet macOS tail takes 7 minutes to process a log file on my system that GNU tail can process in 80 milliseconds. If you're curious you might be able to find out why for yourself: https://github.com/apple-oss-distributions/text_cmds/tree/text_cmds-138.100.3/tail https://github.com/apple-oss-distributions/text_cmds/tree/te... It's presumably based on an old freebsd (circa v3 or v4) version of tail. (it's possibly you may already know this is out there, but it used to be a lot harder to find macos-related source code and they only recently put it all up on github so just in case)
- hnfong 4y agoThe easier way (or a supplementary way) would be to reproduce the slow situation, open Activity Monitor, choose the `tail` process and click "sample process". You'll get a stack trace.