4 ms·
He thinks it makes him look clever, or more likely subtlety wants people to think "wow, this guy thinks something is obvious when Matt Godbolt found it surprisi
by scuff3d 10mo ago
He thinks it makes him look clever, or more likely subtlety wants people to think "wow, this guy thinks something is obvious when Matt Godbolt found it surprising".
This kind of question is entirely useless in an interview. It's just a random bit of trivia that either a potential hire happen to have come across, or happens to remember from math class.
- yeasku 10mo agoTrying to look smart by dissing Matt is not a good idea.
- f1shy 10mo agoAKA you get exactly the opposite…
- mattgodbolt 10mo agoI dunno he can honestly be quite a jerk sometimes
- yeasku 10mo agoBro...
- nickysielicki 10mo agoHave you considered that maybe Matt isn’t all that surprised by this optimization, but he is excited about how cool it is, and he wants readers of all backgrounds to also be excited about how cool it is, and is just feigning surprise so that he can share a sense of excitement with his audience? It’s writing for effect.
- yeasku 10mo agoEverybody who has seen any video of Matt knows that. You can be surprised about things you know for years. For example I am surprised every time I think about js coalescing even tougth I know it for decades.
- nickysielicki 10mo agoThe one that always gets me is what Truffle/JRuby was capable of, ten years ago: https://x.com/chrisgseaton/status/619885182104043520 https://x.com/chrisgseaton/status/619885182104043520 https://x.com/chrisgseaton/status/619888649866448896 https://x.com/chrisgseaton/status/619888649866448896
- nickysielicki 10mo agoWhether they get the question exactly right and can pinpoint the specific compiler passes or algebraic properties responsible for reductions like this is totally irrelevant and not what you’re actually looking for or asking about. It’s a very good jumping point for a conversation about optimization and testing whether they’re the type of developer who has ever looked at the assembly produced in their hotpath or not. Anyone who dumbly suggests that loops in source code will always result in loops in assembly doesn’t have a clue. Anyone who throws their hands up and says, “I have no idea, but I wonder if there’s some loop invariant or algebraic trick that can be used to optimize this, let’s think about it out loud for a bit” has taken a compiler class and gets full marks. Anyone who says, “I dunno, let’s see what godbolt does and look through the llvm-opt pane” gets an explicit, “hire this one” in the feedback to the hiring manager. It’s less about what they know and more about if they can find out.
- scuff3d 10mo agoSo in other words, it isn't "basic and essential optimizations" that you would expect even a junior engineer to know (as your comment implies), but a mechanism to trigger a conversation to see how they think about problems. In fact, it sounds like something you wouldn't expect them to know.
- nickysielicki 10mo agoI didn’t write the GP comment. I wouldn’t call this basic and essential, but I would say that compilers have been doing similar loop simplifications for quite some time. I’d expect any mid to senior developer with C/C++ on their resume to at least consider the possibility that the compiler can entirely optimize away a loop. > In fact, it sounds like something you wouldn't expect them to know. I’d go a step further, I don’t think anyone, no matter how experienced they are, can confidently claim that optimized assembly will or won’t be produced for a given loop. That’s why the best answer above is, “I dunno”. If performance really matters, you have to investigate and confirm that you’re getting good code. You can have an intuition for what you think might happen, and that’s a useful skill to have on its own, but it’s totally useless if you don’t also know how to confirm your suspicions.
- mgaunard 10mo agoI guess what's surprising here is that compilers are able to perform those optimizations systematically on arbitrary code, not the optimizations themselves, which should be obvious to a human.