News for hackers. Stuff that matters.
Re:14,000x Speedup (2015) by mynegation on Tuesday October 13, 2020 @09:27AM (#24765346)
Algorithms are important but are especially powerful in combination of knowing computer architecture and programming language intricacies.

Many years ago I was asked to look at the program written in C++ that calculated Kendall-tau correlation matrix for a large amount of data. Basically Kendall Tau is a robust replacement for Pearson correlation and it had to be calculated for 0.5M^2 elements and calculation of each element needed calculation of Kendall Tau on two series of numerical data of length N. Both M and N were on an order of few thousand and naive implementation has the complexity O(N^2 x M^2). The program ran for 6+ hours.

After looking at C++ I realized that a lot of time is spent just copying data needlessly (a result of not knowing the difference between passing a vector and reference to it) and needless memory allocations and deallocations. I did a rewrite from scratch, keeping the tests, but not copying anything and allocating a minimum amount of memory only once, employing the cache locality, spreading the calculation with OpenMP and finally - realizing that Kendall Tau can be done in O(M^2 x Nlog(N)) I found that out on my own, just by squinting and realizing that calculation of Kendall tau for two series is essentially sorting, but later found out that e.g. scipy implementation uses the same approach.

The resulting program ran for 4 minutes on a 2-core and 4 threads.

Re:14,000x Speedup (2015) by 8ytecoder on Tuesday October 13, 2020 @11:41AM (#24766643)
This is at the very least a clever and involved optimization. Let me tell you the story of my similar 10h to 10min fix. We had this cronjob that was supposed to run every hour, detect all changes to the customers and related table and sync with the marketing saas tool. It was written in Rails and took 10 mins at first. As we grew the time taken by this job also grew linearly. To a point where it took 10 hours and we could only sync the data twice a day. As it turns out the job was loading each user and then scanning for changes. We switched it into a somewhat complex sql query and MySQL ran it in a few mins. Add the additional processing and the whole job now took 10 mins.
Re:14,000x Speedup (2015) by tetha on Tuesday October 13, 2020 @12:51PM (#24767344)
This is when being the guy knowing a few database tricks is fun.

We had one reporting query that ran for 13 hours or so, in a normal web request. Not very successful, but it tried its best. Running this through explain while thinking of daloks revealed some dependent subqueries. Those are the devil in mysql because they are evaluated per row in the outer query. That takes a lot of time very quickly. Eventually we wrangjangled the dependency into a terrifying group by such that the dependent query could be precomputed and the outer query just joins with the result. Boom, runtime down to 2 minutes.

In another case everyone panicked ... until one of my dudes added an index - which took about a day - and slashed runtimes from 18 hour to 12 minutes. Learning to optimize queries on your RDBMS of choice is very powerful.

Re:14,000x Speedup (2015) by karmakaze on Tuesday October 13, 2020 @05:14PM (#24770383)
Saw one of these recently in a query that was ported from PostgreSQL to MySQL. Same thing join-with table-expression to fix it from 6+ hours to seconds. MySQL will sometimes consider a subquery to be 'dependent' even when there are actually no dependent terms and could have been evaluated once.
Re:14,000x Speedup (2015) by hrishios on Wednesday October 14, 2020 @12:45AM (#24773160)
+1 for wrangjangling.
Re:14,000x Speedup (2015) by fwip on Tuesday October 13, 2020 @04:36PM (#24770033)
My first big win came as an intern, when I reduced the big O complexity of an algorithm written by a (very smart) statistician for our paper to O(n^2) instead of O(n^4). This was just driven by realizing that a couple data lookups in an inner loop were themselves O(n^2).

If I recall correctly, that raised the "feasible" value of K from about 4 to about 14 on the hardware at the time, which was more than enough for our purposes. I wanted to keep optimizing, but my boss correctly reminded me that shipping the paper was more important.

Re:14,000x Speedup (2015) by mesarvagya on Tuesday October 13, 2020 @12:03PM (#24766835)
Sounds like classic n+1 problem
Re:14,000x Speedup (2015) by stouset on Tuesday October 13, 2020 @12:18PM (#24766994)
Or more likely, the classic “fetch an entire table from the database and work on it locally” problem that seems endemic in code written by people who don’t understand the capabilities of SQL.

Works great in dev with a local sqlite instance and ten rows. Not so great in prod.

Re:14,000x Speedup (2015) by hinkley on Tuesday October 13, 2020 @12:04PM (#24766848)
I was asked once in an interview what the hardest part of programming was, and I said it wasn't Order of Complexities, it was the C constant within it. Interviewer was not subtle in thinking that was stupid.

My rationale was - and is - that C is not sexy. It's hard to motivate people to look into it, and it's often hard work because a sort algorithm or a lookup table tend to be compartmentalized, while C issues are diffuse - they're literally everywhere, and they don't always show up on a flame graph. On one project I got a 2x improvement in overall performance by fixing issues that weren't visible in the perf output, and would have been invisible on a flame graph (this was before flame graphs).

C is particularly a bigger issue once you consider Amdahl's law. A 20% slowdown in a linear part of the code can show up as a second-for-second slowdown in response times, while a search algorithm that's only a small part of an overall process, or parallelized, you can make it 10 times faster and might only see a 2% improvement in response times. If you avoid allocating more servers, for a new feature, nobody celebrates your achievement. You have to do it wrong the first time for anyone to notice you.

Re:14,000x Speedup (2015) by kadoban on Tuesday October 13, 2020 @12:11PM (#24766899)
I'd argue that none of that is the hardest part of programming, or at least what I'd focus on in terms of what comes up the most and what effects users and developers and suits the most.

Judging by those, the most important hard parts are around planning and estimating work, and correctly understanding when those make no sense, and in validating code for correctness, especially over time.

If we ignore importance and just go with what's the hardest single task: naming things.

Re:14,000x Speedup (2015) by hinkley on Tuesday October 13, 2020 @01:38PM (#24767810)
First, there is no one answer here. When we specialize we take on some 'hard parts' and delegate other hard parts to other people. Civilization is predicated on you and I having different definitions of 'difficult'.

But I think they're of a piece. All of these things are "meatspace" problems. We are constantly fighting the temptation to try to intellectualize the whole process of making software because the center of the problem is trying to interact with a machine. Some don't fight that temptation at all.

You see this problem when people fight automation because they expect everyone to execute a manual process perfectly every time, even when the consequences of failure are very high. They insist that everybody white-knuckle everything and think less of you if you don't agree. They victim-blame. When they're the founding or oldest surviving members of a project, you're gonna have a bad time. People who could fix the problem move on to other jobs.

Naming things is really the same class of problem. A bad name calls to mind assumptions that are not relevant, and you are in constant danger of making category errors every time you think about that part of the code. A bad name becomes a sort of attractive nuisance.

The C problem is a matter of motivating people to do the right thing. Because it's difficult to spot, it's an invisible sin. It rarely comes up in code reviews, so nobody will call you out on it, nobody will make you fix it, finding it after the fact is daunting, and the only people who will care (eg sales) are so often the source of other problems that pleasing them is almost a character flaw. If performance is a feature, then constant time regressions are one of our worst games of whack-a-mole (behind security and internationalization, maybe ahead of sane logging).

[ETA:] I'm just a weirdo who likes to tilt at some kinds of problems I find hard, instead of dumping them on someone else.

Re:14,000x Speedup (2015) by karmakaze on Tuesday October 13, 2020 @05:17PM (#24770416)
The real problem with naming things is that the wrong 'things' have been isolated, if there was a clear understanding of what was being isolated and why the naming part would be easy(er).
Re:14,000x Speedup (2015) by SAI_Peregrinus on Friday October 16, 2020 @09:59AM (#24800866)
There are two hard problems in computer science: naming things, cache invalidation, and off-by one errors.
Re:14,000x Speedup (2015) by amenod on Tuesday October 13, 2020 @03:06PM (#24769005)
> On one project I got a 2x improvement in overall performance by fixing issues that weren't visible in the perf output, and would have been invisible on a flame graph (this was before flame graphs).

I assume you mean that these improvements would not be visible on a flame chart because they were not in perf output? (assuming one was built from the other?)

Flame graph by definition shows where the time is spent and is just a (great, imho) visualization of this data. Some people seem to have a beef with it, but their issues are invariably tied to the way the original data is gathered.

Re:14,000x Speedup (2015) by hinkley on Wednesday October 14, 2020 @08:36AM (#24775790)
This got longer than I intended, but that just illustrates that the rabbit hole is deeper than many people are willing to go.

The data can be wrong in a number of dimensions. In general, code that gets called the most sometimes get underreported. Look at invocation counts. Ask questions.

One, they can clear the CPU cache, causing sibling functions to be overreported (one of many sources of how changing a slow function may bring less of an improvement than expected). This shows up strongest when I‘ve gotten a 10% runtime improvement from fixing a function reported as 5% of total time, or a 10x reduction in time from removing half the calls to a remote service.

Two, duplicate or idiomatic code will be scattered across different parts of the code stack, reducing the apparent magnitude of a pattern of logic below the threshold of attention of most people. Code that is in four places may represent 5% of total time and not get looked at, even if it’s an easy fix. The nickels and dimes add up quickly.

Three, functions that operate near the limits of the clock resolution will be counted properly but the cumulative timing rounded down, again putting it below the noise floor for most people. I’ve made a lot of hay re-sorting the results by invocation count and benchmarking changes to functions that never hit the top 20 list.

And last but not least, functions that create but don’t destroy their own memory allocations end up shedding timing that gets picked up by the recipients, homogenizing the timing graph. In particular in GCed languages, a function that is called in a loop that exhausts most but not all of the free heap will invariably end up stalling out in the next phase of a large calculation.

With all four of these, there are several failures of imagination I commonly saw. A flat timing graph is taken as evidence that it is time to stop optimizing, even if the target improvement has not been met. When the “tent poles” are even, getting people to care how tall they are is challenging. Few people will make six changes to the code to achieve a 10% speed up. The Rust compiler may be the first time I’ve witnessed anyone else brag about a 1% performance gain, other than me. They either don’t do it, or they apologize for achieving so little. 10% is 10%, and I don’t care where you found it, if your code quality is high enough. And perhaps most importantly, speed improvements are multiplicative, not cumulative. Use a time budget the way game devs do. If an interaction takes 10x as long as your target, every method that takes 0.5% of current run time represents 5% of your target. This is, in particular, how you spot duplicated slow code. You ignore them at our peril.

Particularly in the era of QA cycles, using a “zone defense” (optimizing one module at a time, instead of going after tall tent poles) netted a higher rate of return per hour of labor and a much larger cumulative improvement, on its own merits and by increasing the budget allotted to perf. It seems concentrating the changes in one area at a time decreases optimization fatigue. On two projects I kept that initiative alive for more than two years, and I was the one that gave up because I had cycled around the entire system and was finding few things to correct (you only learn new tricks so fast, and they go asymptotic eventually). Everyone came to expect every release to be a bit faster than the previous, and I got feedback that this narrative increased sales, and manager buy-in. People will take a chance on you when they like where you’re going, even if you haven’t gotten there yet. Narrative matters, if they trust you, and usually you have to earn it.

Re:14,000x Speedup (2015) by amenod on Thursday October 15, 2020 @12:36PM (#24790538)
Yes, I agree with you - I just don't see that as a failure of flame charts.

You still need to understand how the data was gathered and what it really means. It is also true that flame charts are more useful on projects that are not yet heavily optimized; they clearly show the parts that are very slow compared to others. And when you don't see anything else that can be optimized, it doesn't mean that everything is optimal - the limit is imagination (and knowledge), not the problem space.

Re:14,000x Speedup (2015) by arethuza on Tuesday October 13, 2020 @12:13PM (#24766934)
Out of interest, did they say what they thought the hardest part of programming is?
Re:14,000x Speedup (2015) by mynegation on Tuesday October 13, 2020 @12:24PM (#24767046)
Just one hardest part? Could be naming things and off by one errors.
Re:14,000x Speedup (2015) by joshuak on Tuesday October 13, 2020 @12:43PM (#24767252)
... and cache invalidation
Re:14,000x Speedup (2015) by nullsense on Tuesday October 13, 2020 @05:58PM (#24770814)
...and off by one errors
Re:14,000x Speedup (2015) by z3t4 on Tuesday October 13, 2020 @12:58PM (#24767418)
What is the C constant?
Re:14,000x Speedup (2015) by vonmoltke on Tuesday October 13, 2020 @01:30PM (#24767726)
If I understand hinkley's point correctly, it's the constant multiplier (and, in some cases, lower-order terms) that conventional complexity analysis handwaves away as irrelevant because it only looks at the limit as input size goes to infinity.
Re:14,000x Speedup (2015) by naruvimama on Tuesday October 13, 2020 @01:31PM (#24767737)
I guess the op meant the C as in

Total time = nX + C

No matter how much you optimize X (n here is for instance the number of items), if C is significant then it matters. It is usually harder to optimize the constant C in the OP's experience.

Re:14,000x Speedup (2015) by brilee on Tuesday October 13, 2020 @09:38AM (#24765440)
I realized the same thing when trying to compute F1-optimized thresholds; scanning through all possible threshold scores is O(n^2) but computing f1 score inline while scanning through the sorted array is O(n).

https://www.moderndescartes.com/essays/auc_intuition/ is my writeup on why the sorting approach is the most economical way to approach this sort of problem

Re:14,000x Speedup (2015) by Phemist on Tuesday October 13, 2020 @06:53PM (#24771238)
Interesting! Thanks for the write-up. In the field of Biometrics we often use the library BOB to compute scores like AUC's and EER's, or other measures over stuff like DET curves.

For some practical work I was doing, BOB (and SK learn) proved too slow for my liking. I am currently unable to provide much more detail, but I used a similar insight to yours (mine was the amortization of sorting costs to have a better average time complexity) in a library I built for calculating empirical, bootstrapped, confidence intervals for EER's.

https://github.com/feerci/feerci

For massive amounts of decision scores, like millions, this method can give you confidence intervals on EER's where no other library currently in use can. Unfortunately, I have not yet found a theoretical basis for this method, and suspect it might actually break down under some trivial smaller cases. Also, DET curves and their derived measures remain a tough cookie to crack.

Considering AUC's and EER's are somewhat tightly related, I'm thinking this method could also be applied to AUC's.

Re:14,000x Speedup (2015) by lmm on Tuesday October 13, 2020 @09:53AM (#24765540)
So did you measure how much of the speed improvement came from your careful memory copying tuning and how much came from the algorithmic change?
Re:14,000x Speedup (2015) by mynegation on Tuesday October 13, 2020 @10:59AM (#24766193)
At the time, yes, but I do not have those numbers anymore. Trying my best to remember - I would estimate that the speedup of 360 / 4 = 90x is approximately: 4x multithreading (it was pretty linear speedup), 7x the algorithm and 3x the memory inefficiencies.

EDIT: fixed my math, thank you andruby

Re:14,000x Speedup (2015) by andruby on Tuesday October 13, 2020 @11:07AM (#24766282)
Sorry to correct your math here, but going from 6 hours (6*60=360 minutes) to 4 minutes is a 90x improvement, not 900x.
Re:14,000x Speedup (2015) by ath92 on Tuesday October 13, 2020 @12:40PM (#24767226)
Interestingly, a speedup of 2 orders of magnitude seems to be about what you'd expect if you only apply the algorithmic optimization (going from N^2 to Nlog(N) with N being in the range of a few thousand, like OP said)
Re:14,000x Speedup (2015) by mynegation on Tuesday October 13, 2020 @01:02PM (#24767459)
Like I mentioned - my memory is pretty hazy about the specific speedups.

Yes, N^2 to NlogN feels like it should be a bigger factor, but remember that constants in front of this matter. You are replacing 2-level nested but very straightforward loops that rip through cached memory at blazing speed without any disruption to CPU pipelines with a single loop that involves quite a bit of condition checking and array element swaps (cache is busted, pipelines are busted - conditions are very hard to predict). You gain some, you lose some.

Re:14,000x Speedup (2015) by TYMorningCoffee on Tuesday October 13, 2020 @10:03AM (#24765625)
Yeah. The commenter only gave the numbers when both the constant factor and the improved algorithm were applied.

It would be interesting to see them applied separately. The commenters claim that both are important has not been shown by his example yet.

However the results are impressive. Great job with the solution.

Re:14,000x Speedup (2015) by mumblemumble on Tuesday October 13, 2020 @10:12AM (#24765698)
Re:14,000x Speedup (2015) by monksy on Tuesday October 13, 2020 @01:14PM (#24767562)
That was a great write up explaining about not seeing the forest for the trees. However, it is still infuriating that we're getting these leetcode questions in interviews to see how much you can hack and optimize a toy problem. (As if you had lots of time to think about it and work through it)
Re:14,000x Speedup (2015) by mynegation on Tuesday October 13, 2020 @12:09PM (#24766891)
Ha! Great story, thank you! Clearly shows that computational complexity by itself is not very useful without knowing the assumptions. It is one thing to see substring search and immediately pattern match it to something from CS course like Boyer-Moore or Knuth-Morris-Pratt, but these algorithms require pre-processing that makes sense only if you know you are going to search for the same pattern repeatedly. Pure library function cannot make that assumption, and REPNE instruction is just an icing on a cake.
Re:14,000x Speedup (2015) by ghusbands on Tuesday October 13, 2020 @03:55PM (#24769617)
> pre-processing that makes sense only if you know you are going to search for the same pattern repeatedly

The pre-processing is typically worth it if you're searching through a large string, even just once.

Re:14,000x Speedup (2015) by antisthenes on Tuesday October 13, 2020 @12:06PM (#24766862)
That was a great read for someone who's used VBA to solve business cases, including InStr.

Anecdata, but most of my strings were indeed short (searching for manufacturer SKUs inside arrays of other SKUs).

Re:14,000x Speedup (2015) by neves on Tuesday October 13, 2020 @09:52AM (#24765526)
This is a usual problem with C++ and why I hate it. There's a lot going on under the hoods, and you must be really knowledgeable of the language to prevent stupid things. Following some idioms you can really avoid it, but it is useless since your coworkers will fall into the language traps.
Re:14,000x Speedup (2015) by vidarh on Tuesday October 13, 2020 @11:00AM (#24766201)
Knowing if you're copying or passing references is essential to understanding most languages that supports both.

It's scary how many people are unaware of it, though.

Not nearly as dramatic as the example above, but I once cut the time spent on page generation for a commercial CMS by 30% my first day in a new job by realising they did excessive new allocation of strings instead of concatenation (which will amortise the allocations by allocating more space than needed in most C++ implementations).

I find it quite disturbing, because, while I prefer to use Ruby these days, C++ documentation is really explicit about guarantees provided by both the language and the standard library with respect to things like memory behaviour and algorithmic complexity.

There's if anything less going on under the hood with C++ that you're not explicitly told about than in most modern languages.

Re:14,000x Speedup (2015) by godelski on Tuesday October 13, 2020 @12:17PM (#24766970)
One thing I tell people is that beginning a good C/C++ programmer made me a much better python programmer and makes it substantially easier to pick up other languages. It's not so specific to the language being C as much as it is learning about memory and the what you learn by constantly shooting yourself in the foot because you make dumb mistakes (I still think mistakes are the best way to learn).
Re:14,000x Speedup (2015) by neves on Tuesday October 13, 2020 @03:13PM (#24769095)
I agree, but a simple automatically defined copy constructor can spread havoc in a code base.
Re:14,000x Speedup (2015) by qayxc on Tuesday October 13, 2020 @10:00AM (#24765597)
I'd argue that not knowing the language you're working with is a problem that's not exclusive to C++.

There's so much more going on under the hood of more high level languages, that writing faster code is straight up black magic [1].

[1] https://stackoverflow.com/questions/28723658/python-why-is-i...

Re:14,000x Speedup (2015) by throwaway894345 on Tuesday October 13, 2020 @10:19AM (#24765778)
Yes, you must always know your language, but mastering (for example) Go is a lot easier than getting a cursory understanding of C++ (i.e., enough to write correct code for non-toy applications). You can get a cursory understanding of Go in a few hours and you can master it in 1-2 months. It would be months and years in C++, respectively. C++ is just a much larger, more complex language, so there is a lot more to know. It's not that C++ is inherently bad--some of that complexity allows C++ to be faster and more powerful than Go; however, we can't pretend that the two are equivalent with respect to their ease of learning or number of footguns.
Re:14,000x Speedup (2015) by qayxc on Tuesday October 13, 2020 @10:28AM (#24765850)
I agree in general, but knowing the difference between pass-by reference and pass-by value is C++ 101.

Mastering C++ isn't even required to be productive using it, since there's no need to use all the language features simply because they exist. This also avoids the majority of footguns.

Re:14,000x Speedup (2015) by throwaway894345 on Tuesday October 13, 2020 @11:12AM (#24766330)
> I agree in general, but knowing the difference between pass-by reference and pass-by value is C++ 101.

I agree. But the scientific computing community includes a lot of people who have no exposure to computing at all, so that vectors are copied when passed by value (as opposed to a fat pointer a la Go slices) is a performance foot gun for these new users. For that matter, a lot of people coming to C++ from any higher level language will likely be tripped on on this for a while.

> Mastering C++ isn't even required to be productive using it, since there's no need to use all the language features simply because they exist.

Right, I was distinguishing between "mastering" and "knowing enough to be productive". I'm asserting that you can master Go in far less time than is required to be merely productive in C++ (granted, I'm assuming "productive" means "you're not regularly introducing memory leaks, segfaults, etc" i.e., "you understand memory management best practices in C++"). Specifically, I think it takes 1-2 months for a newbie programmer to become a master of Go and ~6 months to become merely "productive" in C++ (bear in mind that even figuring out how to build non-trivial C++ programs is itself a herculean feat).

Re:14,000x Speedup (2015) by gumby on Tuesday October 13, 2020 @11:26AM (#24766493)
For a systems programming language the part of C++ that most people need to know isn’t huge.

There’s a lot in c++ that only exists for back compatibility and you don’t need to use it. There’s also a lot of infrastructure so library writers can write very efficient generic code. Most people are not writing libraries and don’t need that stuff.

Re:14,000x Speedup (2015) by sdenton4 on Tuesday October 13, 2020 @11:50AM (#24766724)
You got all the backwards compatibility stuff, though, if you're code base is older than today. Or if you've got co workers who learned on c++11 instead of c++19...

Also, templates, and the indecipherable errors they throw. And cpp memory handling errors are one of the largest sources of security holes.

I'm convinced that apologising for cpp is basically Stockholm syndrome. These are things we absolutely would not accept in a new language, but we must, because it's what we've got. Rust can't win fast enough, I say...

Re:14,000x Speedup (2015) by ncmncm on Wednesday October 14, 2020 @04:03AM (#24774291)
It would be great if a modern language could match C++, but none is on the horizon.

Rust is powerful enough to do a lot of what C++ is used for, but not the hardest things. There are libraries you write routinely in C++ that you can't code in, or call from, Rust, and never will. The gap will widen with time. Rust is focused on low-level safety at the expense of library power, but you get safety in C++ by coding using more powerful and safe libraries, so C++ comes out ahead in the end.

Rust is a way better language than Go or Java. It would be excellent if Rust could displace them, or even just one of them.

If its adoption rate were to increase by maybe two or three orders of magnitude, it could survive. But the Rust core team seem not interested in doing what would be needed to get that much adoption, and hype alone won't get it there.

Rust's place will be secure when more complaints are written about it than paeans.

Re:14,000x Speedup (2015) by throwaway894345 on Tuesday October 13, 2020 @02:11PM (#24768150)
I would even say that simply knowing which things are essential and which are "legacy things for backwards compatibility that most people don't need to know about" is nontrivial, and I'm not even sure that there is substantial consensus among the C++ community about exactly what is in the "legacy/compatibility things" bucket (no doubt there's wide spread agreement that some features are in this bucket, but I imagine there are a lot of features that are controversial).
Re:14,000x Speedup (2015) by User23 on Tuesday October 13, 2020 @11:54AM (#24766762)
C++ has a famously complex standard though, to the point that, last I checked, there are no fully standards conforming C++ compilers. I know one member of the standards body and he is an excellent software engineer, a subject matter expert, and just wicked smart too, and he still confesses he doesn't really understand C++. There's a reason why Google doesn't actually have C++ as a supported language, but rather a curated subset thereof that's governed by their house style guide.
Re:14,000x Speedup (2015) by qayxc on Tuesday October 13, 2020 @12:52PM (#24767368)
I concur, but using and knowing a reasonable subset is enough to be productive.

Rust has its own problems and pitfalls as well, and I doubt that people who don't understand pass-by value vs pass-by reference and its implications will be happy with fighting the compiler over ownership issues.

Implementing a doubly linked list comes to mind - trivial in C++ - a brain twister in Rust and apologists will hide behind statements like "they're almost always the wrong choice anyway" or they're "just used pedagogically" [1].

A cynic could interpret that as Stockholm Syndrome as well.

[1] https://codereview.stackexchange.com/questions/204183/doubly...

Re:14,000x Speedup (2015) by mynegation on Tuesday October 13, 2020 @10:49AM (#24766088)
C++, while complicated, is actually pretty transparent about it. The difference between pass-by-value and pass-by-reference is one sigil, but at least you see it there and you have at least some idea that it is there for a reason.

Compare it with lazy evaluation languages like Haskell or declarative languages like SQL where oftentimes you have to run query planner explanation to troubleshoot the performance problems.

Re:14,000x Speedup (2015) by milesvp on Tuesday October 13, 2020 @11:16AM (#24766374)
+1 for sql. I once was looking into a slow query and had to know that ordering text field in mysql requires a filesort regardless of how much data was involved. which means touching a disk. Was easy enough to make a schema change to a varchar small enough not to also trigger a filesort. But learning that required several hours of scouring documentation and making sure the schema change wasn’t modifying the requirements significantly.

Also what’s fun is that the data in the tables can change the explain plan. I got to see this myself when dealing with dev vs prod data.

Re:14,000x Speedup (2015) by necovek on Tuesday October 13, 2020 @02:22PM (#24768368)
Knowing the basics of CS would surely help in set the expectation for such "SQL" (or rather, RDBMS) behaviour: the problem is the problem of sorting a very large array of strings, which is unsurprisingly a hard one.

The very basic experience with RDBMS would point you at a better solution: indexes. Not sure about MySQL or standard SQL, but with Postgres you can keep an ordered index that will be used in an ORDER BY query. It's a common trick employed in programming in general: trade the update/insert cost for query cost (indexes take time to update, but querying is then fast).

Re:14,000x Speedup (2015) by Tomis02 on Wednesday October 14, 2020 @05:17AM (#24774705)
> Also what’s fun is that the data in the tables can change the explain plan.

1. This change tends to be in your favour, not against you.

2. Data is important, not the code. Of course the plan would change if your data changes. That is the point of the query planner, to find the most efficient way of retrieving the data, based of course on the contents of the database.

I agree that you need a good knowledge of your database in order to be effective. Just like with C++, for example. Unfortunately we're not at the point where we can achieve optimal results without understanding the fundamentals, regardless of the programming paradigm.

Re:14,000x Speedup (2015) by naruvimama on Tuesday October 13, 2020 @01:41PM (#24767839)
The vast majority of SQL is written or managed by business users. It is a good idea to let the engine optimize the code.

And it is a dsl the planner is expected to be very good. Perhaps the next version will always fix it.

Re:14,000x Speedup (2015) by nullsense on Tuesday October 13, 2020 @07:37PM (#24771590)
It can't automagically not do stupid things if you feed it a query that will make it do stupid things. You still have to know certain things about how queries will try to fetch data.
Re:14,000x Speedup (2015) by dahfizz on Tuesday October 13, 2020 @08:20PM (#24771870)
I really have to disagree.

There is a lot going on under the hood regardless. That's how computers work. Your Python script has to deal with all the same memory allocation and cache locality issues.

C/C++ just gives you the opportunity to see what is happening under the hood and tune it.

Re:14,000x Speedup (2015) by bufferoverflow on Tuesday October 13, 2020 @10:02AM (#24765614)
What he described has nothing to do with C++, but with the inefficient algorithm that was chosen.
Re:14,000x Speedup (2015) by formerly_proven on Tuesday October 13, 2020 @10:59AM (#24766195)
There's very little going on under the hood with C++, if it even has a hood.
Re:14,000x Speedup (2015) by andi999 on Tuesday October 13, 2020 @12:56PM (#24767401)
Vtable and vtable pointer is under the hood.
Re:14,000x Speedup (2015) by not2b on Tuesday October 13, 2020 @03:10PM (#24769053)
Yes, but any C++ programmer who expects to be hired will have a good understanding of vtables and vtable pointers. They are a lot less tricky to reason about than, say, thunks in Haskell.
Re:14,000x Speedup (2015) by tome on Tuesday October 13, 2020 @04:18PM (#24769866)
What makes you so sure about that?
Re:14,000x Speedup (2015) by ncmncm on Wednesday October 14, 2020 @04:15AM (#24774347)
Those are trivial. And have little effect on performance. And are hardly used in good programs.

In practice they mainly displace function pointers.

Re:14,000x Speedup (2015) by andi999 on Wednesday October 14, 2020 @04:18AM (#24774368)
They might destroy your cache lines though.
Re:14,000x Speedup (2015) by sdenton4 on Tuesday October 13, 2020 @02:27PM (#24768452)
Meanwhile, there's a perception that machine learning is hardware-bound for speed increases, which just isn't true.

I work on a pretty heavy ML system, which a year ago took about a month to 'fully' train. Today we're down to 25 hours training time using the same hardware, based mostly on improvements to the model. The improvements are coming from a combination of signal processing tricks and tricksy model changes. Inference is similarly much faster, too...

Re:14,000x Speedup (2015) by EmbarrassedFuel on Tuesday October 13, 2020 @04:15PM (#24769826)
Sounds interesting, would you be able to share anything about the signal processing tricks?