5 ms·
Cool anecdote from inside article > A seasoned performance engineer was looking through Strobelight data and discovered that by filtering on a particular std::
by varunneal 2y ago
Cool anecdote from inside article
> A seasoned performance engineer was looking through Strobelight data and discovered that by filtering on a particular std::vector function call (using the symbolized file and line number) he could identify computationally expensive array copies that happen unintentionally with the ‘auto’ keyword in C++.
> The engineer turned a few knobs, adjusted his Scuba query, and happened to notice one of these copies in a particularly hot call path in one of Meta’s largest ads services. He then cracked open his code editor to investigate whether this particular vector copy was intentional… it wasn’t.
> It was a simple mistake that any engineer working in C++ has made a hundred times.
> So, the engineer typed an “&” after the auto keyword to indicate we want a reference instead of a copy. It was a one-character commit, which, after it was shipped to production, equated to an estimated 15,000 servers in capacity savings per year!
- JoshTriplett 2y agoIt's a cool anecdote. It's also a case study in heavyweight copies being something that shouldn't happen by default, and should require explicit annotation indicating that the engineer expects a heavyweight copy of the entire structure.
- mhlakhani 2y agoI don’t know if that would have helped here, if memory serves me right: 1. The copy was needed initially 2. This structure wasn’t as heavy back then … over time the code evolved so it became heavy and the copy became unnecessary. That’s harder to find without profiling to guide things
- ehsankia 2y agoIf it's safety/correctness versus performance, I think the default should be the former. Copying, while inefficient is generally more correct and avoids hard-to-debug errors. It's the whole discussion about premature optimization. I'd rather make a copy than make sure the array is not mutated anywhere ever.
- ltbarcly3 2y agoYes, everyone agrees with you. The claim you responded to was that you should have to be explicit, because it is very easy to unintentionally copy. For example, it is easy to copy when there is never more than one live pointer to a datastructure. It's easy to copy when you allocate a resource in a function and return it, which makes the original an orphan which is then immediately freed. It's extremely easy to make a mistake which prevents move from working and you have to go back and carefully check if you want to be sure. It should be trivial to just say "move this" and if something isn't right it's an error at compile time, rather than just falling back to silently being wasteful.
- School-Cotton 2y agoThis exact problem is basically why Rust exists.
- JoshTriplett 2y agoI'm not saying it should silently alias any more than it should silently copy. It should give an error, and require the developer to explicitly copy or explicitly alias.
- mhlakhani 2y agoThat one diff blew my mind when I saw it. It’s a prime example of that story about “you paid me a lot of money to know where to fix that pipe”
- howlallday 2y ago[flagged]
- vosper 2y agoTired vote-bait quote.
- Bjartr 2y agoOnly because the Overton window has shifted enough to normalize it.
- howlallday 2y agoImagine how much server capacity we could save if we didn't waste the equivalent electrical consumption of Belgium convincing your mother she needs more garbage from Temu.
- phyrex 2y agoAnd then how would we pay for that server capacity?
- deleted 2y ago[deleted]
- howlallday 2y ago[flagged]