by varunneal · 1y ago · 0 comments
> 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!
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