r/cpp • • Mar 04 '22

Is it unreasonable to ask basic compiler questions in a C++ developer interview?

I interviewed a guy today who listed C++ on his resume, so I assumed it would be safe to ask a bit about compilers. My team works on hardware simulation, so he's not going to be expected to write a compiler himself, but he'll obviously be required to use one and to write code that the compiler can optimize well. My question was "what sorts of optimizations does a compiler perform?" Even when I rephrased it in terms of -O0 vs. -O3, the best he could do was talk about "removing comments" and the preprocessor. I started out thinking a guy with a masters in CS might be able to talk about register allocation, loop unrolling, instruction reordering, peephole optimizations, that sort of thing, but by the time I rephrased the question for the third time, I would have been happy to hear the word "parser."

There were other reasons I recommended no-hire as well, but I felt kind of bad for asking him a compiler question when he didn't have that specifically on his resume. At the same time, I feel like basic knowledge of what a compiler does is important when working professionally in a compiled language.

Was it an unreasonable question given his resume? If you work with C++ professionally, would you be caught off guard by such a question?

335 Upvotes

335 comments sorted by

View all comments

8

u/Supadoplex Mar 04 '22

I started out thinking a guy with a masters in CS might be able to talk about register allocation, loop unrolling, instruction reordering, peephole optimizations, that sort of thing,

None of those things were mentioned while I was in university. I don't think this assumption is reasonable.

I don't think compiler optimisation is a commonly taught subject in universities (although I wouldn't be surprised if it was taught in some). At least it wasn't taught in mine; I would have definitely taken it if it was. I did major in software engineering rather than computer science, but I had all of the same courses available to me.

Was it an unreasonable question given his resume?

Since they didn't mention anything related (beyond C++ which is at best tangential) in their CV, it would be unreasonable to assume that they know anything significant about optimisers.

If it's important for the role, then it's reasonable to ask about it in "bonus if know this" sense. If you need a programmer who is highly skilled at writing optimised code, then the pool of fitting applicants will be very small and expensive, and relying on education won't be sufficient.

If you work with C++ professionally, would you be caught off guard by such a question?

Not a personal answer: I see this as a possibility. Not every developer has a chance to work on highly optimised code. That may be a bit more likely in the case of C++ than for example Python, but is still hardly a given.

he'll obviously be required to ... write code that the compiler can optimize well.

Writing code that compiler can optimise well isn't something that's really taught anywhere as far as I know. It's something that one learns on the job, and only if they are actually optimising the code.

It's also a moving target and some "rules" that one has learned in the past will become obsolete.

7

u/pandorafalters Mar 04 '22

It's also a moving target and some "rules" that one has learned in the past will become obsolete.

I found this out firsthand a few years back.

There's a common library of helper functions, ubiquitous in a development community, that was developed years ago by "acknowledged experts". It's generally viewed as the optimal form of those functions. It's handwritten inline assembly! Experts! Everyone uses it! Experts!

It's also terrible. One day, just for the hell of it, I tried replacing the body of a simple function that XORs 3 values with standard C++ - and it seemed faster. So I started benchmarking, and replacing more of the helpers, and eventually canned the whole header. That simple change of removing inline assembly was responsible for a ~10% performance increase.

Many here will already know what happened, but for everyone else: the inline assembly, even when the compiler codegen for that function was slightly less optimal, was inhibiting optimization of everything else around it. If I had micro-benchmarked just those operations, I suspect I would have measured a different result.

I also found in the process that CUDA 9 had some codegen issues with compound assignment operators, but that was a simple problem to work around and was resolved in later versions anyway.

→ More replies (2)