Every time I can remember that the finance people have become more important to a company, it has led to the disappearance of the internal culture geared towards excellence that got a company to that point in the first place.
I guess it's simply the externalities issue. Finance people optimize finance, which among other things results in improved efficiency. But despite best intentions to map out all incentives that matter, it always fails to consider some aspects. Focusing on short-term profits, ignoring privacy, security or pollution because it's free, lobbying for favourable legislation that hampers competitors, etc.
These are things that don't show in a spreadsheet unless you're explicitly incentivized to look at them. But that's never the case because the number of KPIs is always finite while there are infinitely many aspects that could potentially be subverted.
Why does "optimizing finance" improve the efficiency in an engineering company? Seems to me like "optimizing finance" could be absolutely detrimental for the bottom line.
It’s largely true. I believe Steve Jobs had some talk about this phenomenon; basically, at some point, the scale of an organization means the product people make less of an impact than the sales / finance people, and they slowly take over.
Then over the span of a few decades, what’s left is a shallow organization without real innovation.
That's what they're afraid of, and that's one of the reasons why they're doing the big management reorganization - too many managers leads to lots of overhead instead of excellence.
I once read “The Joy of Living” by Yongey Mingyur Rinpoche. It should come with a warning. It broke me for a year. I’m actually grateful for the existential crisis it caused me. But it was a brutal experience at first.
I had a similar experience with Derek Parfit's "Reasons and Persons", but he offers some solace:
‘When I believed [that personal identity is what matters], I seemed imprisoned in myself. My life seemed like a glass tunnel, through which I was moving faster every year, and at the end of which there was darkness. When I changed my view, the walls of my glass tunnel disappeared. I now live in the open air. There is still a difference between my life and the lives of other people. But the difference is less. Other people are closer. I am less concerned about the rest of my own life, and more concerned about the lives of others.
When I believed [that personal identity is what matters], I also cared more about my inevitable death. After my death, there will be no one living who will be me. I can now redescribe this fact. Though there will later be many experiences, none of these experiences will be connected to my present experiences by chains of such direct connections as those involved in experience-memory, or in the carrying out of an earlier intention. Some of these future experiences may be related to my present experiences in less direct ways. There will later be some memories about my life. And there may later be thoughts that are influenced by mine, or things done as the result of my advice. My death will break the more direct relations between my present experiences and future experiences, but it will not break various other relations. This is all there is to the fact that there will be no one living who will be me. Now that I have seen this, my death seems to me less bad.’
I think we could summarize all as follows: _everything_ is inter-connected and hence influences its surroundings and hence everything, indirectly. Some connections (in-brain) are stronger/wider than others (human to human etc).
Sharing more: It shattered my prior beliefs about who "I" thought I was. When I read certain passages from the book, I knew it was true. It hurt my ego because it was undeniable. My old belief system was floored. My ideas about myself and others was insufficient. That shattered "me".
In many ways, it probably just helped me to be more compassionate and accepting of my situation and that of others. You cannot really put a price on wisdom like that and I guess for some people, getting to that point doesn't come without collateral ?
"Eastern philosophy can be confronting for those that have not been exposed to it and that meditation isn't jut by default healthy for everyone. Before proceeding, especially if you're prone to any kind of mental illness, make sure you have a strong support network around you before proceeding" ?
Maybe there was some warning in the book, but I was young and keen enough that I would've just heeded that.
Even the author of the books father is a renowned meditation teacher, I'm sure that was helpful.
I read it last year, enjoyed the book, no existential crisis.
I already subscribed to the idea of the self and identity being independent and constructs. A lot of reflection around that and physics in younger years maybe helped.
When understanding a new "magic", there's this beautiful moment when you grok it, and the abstraction poofs away.
It's when you take apart a mechanical clock and keep looking for the time-keeping part, until you figure out that there isn't a time-keeping part in there, it's just gears and a spring.
It's when you learn about integrated circuits and full-adders, and keep trying to understand how a bunch of transistors can do Mathematics, until you figure out that there isn't a mathematics-doing part in there, it's just circuits and wires, arranged in a way that makes the voltages come out right.
It's when your understanding of the top-down structure snaps together with the bottom-up mechanics of the building blocks. There's no space left for the ghost in the machine to haunt, and you go "Oh. huh".
I live for that moment.
I went through an EE degree instead of a CS degree in undergrad specifically so I could peel back this magic and really understand what's going on, to some detail, down to the electromagnetism level. It is indeed a very freeing feeling to be resting atop so many layers of abstractions, with the understanding that if you ever had to, you could go down to any one of them and kind of feel your way around.
I think for me the biggest magic-killing moment was when I realized that CPU clock cycles, timing trees, etc. were all just ways for us to shoehorn a fundamentally analog thing (how much voltage is in area X?) to a digital thing (does area X have enough voltage? yes? OK, call it a 1 and let's move on already!). Somehow to me that feels like the ultimate "leaky" abstraction, although of course decades and trillions of dollars have gone into making it ever more watertight for 99.99-several-more-9s% of the time. At least to the end user. Your mileage may vary if you're a TSMC researcher or something, of course.
I've always felt the whole binary/digital thing was one of the most clever bits of compromise with the real world I've ever seen.
You have this thing, you want to be able to translate its value into something useful. In this case, the amount of voltage in a circuit to a number. And you spend so much time trying to make sure the voltage level passed is rock solid, that your read is equally solid, etc. Until you realize that you'd have to invent so many more industries just to do this one thing that you just give up and say the only thing you can know with certainty is that there is or is not voltage passing through the circuit.
Then you need to be able to translate "ON" and "OFF" into actual usable values. And eventually coming down to a base 2 counting system so that 4 circuits gives you 16 distinct values seems obvious in hindsight, but had to be a revelation when they realized it.
Bingo, precisely. I keep using this compromise as a foundational example when I talk to my wife (currently doing a CS degree) about why binary stuff, specifically, keeps coming up in her stuff. 2 is a magic number in computing because it is the Great Compromise we made with reality to get it.
Every now and then people here bring up more exotic paradigms, like ternary computing, and yes! In an ideal world the more phases you can detect the 'better', all the way up to infinity (pure analogue computing). But the difficulty curve to scale anything besides base 2 to where base 2 computing currently is is, at least for our current understanding in physics, materials science, etc., way higher.
Actually, Leibniz came up with the dual/binary system as being ideal for computation 300 years ago roughly around the same time he built his mechanical calculator, long before there was any chance of there being programmable computers.
I work with FPGAs and embedded systems occasionally, and you have no idea how amazingly watertight the phone/desktop/server CPU abstraction is in comparison to what you get the moment you do something slightly weird. A combination of the chips, the firmware, and the OS does so much work to give you the abstraction of "machine runs code and it just works."
There's a paper from the 1990s of someone trying to do neural net-type things to construct an FPGA, and it gets really out there, like 'this gate isn't actually connected to anything but if we change anything about it the laws of electromagnetism cause the whole thing to stop working' weird. FPGAs are fascinating little dudes, esp in domains like HFT where their speed directly translates into dollars, but I totally believe you here.
for me, it was latches and creating a CPU which instructions could be fed into. but it wasn't a "lost the magic" feeling, it was a "that's amazing!" feeling.
While the Foundation series is what's best known nowadays, the Suzan Calvin and Elijah Bailay stuff, and more generally everything set before the Galactic Empire even exists in Asimov's fictional timeline is where Asimov is at his best.
That's the difference between technology magic and illusionist magic, When you see how the trick is done with illusions it's always a bit of a letdown because the answer is usually prosaic, the 'magic' vanishes and it becomes a trick.
When you understand how a piece of technology works you get that beautiful moment.
I've never got that. I feel the same way in either case, if your trick was easy everybody would do it. Sleight of hand tricks for example, if you're good they're completely seamless, I could never hope to reproduce and yet I know exactly how it's done.
Take that Penn & Teller trick where the live audience is just lying - that's a bit lazy, we're not supposed to have some great admiration for this trick they're just showing you it's an option to just have the live audience lie to the recorded audience and that "works". Whereas their transparent version of cups and balls is the opposite, you must be a sleight of hand master or this won't look like anything.
My wife and I are part time magicians. In my experience, people who share your mindset become magicians.
At the risk of just repeating exactly what the person you're replying to wrote: The reason that non-magicians often feel let down when they find out how a trick is executed, is that it often feels like an insult to their intelligence. Magic toys with and exploits your assumptions. As soon as you find out that those assumptions were incorrect, and that you were just lied to by a prop (for example), your experience and perception of that illusion goes from "OMG" to "oh, that's all?"
What we want the methods to be is some grandiose Ocean's 11 like "heist" with tons of sneaky maneuvers and difficult sleight of hand ... but MOST magic tricks, including the ones that Penn & Teller fool you with (not the ones where they tip the method) are not that.
Penn & Teller have said themselves that (paraphrasing): "if the method is more interesting than the trick, the trick is not very good ... and that's when we show you the method. But the tricks we actually want to fool you with are just a bit of gaffer tape and a lie."
The fact that you say that you appreciate magic tricks that involve a lot of sleight of hand, or require technical mastery, kind of supports what we're saying. Most magic tricks aren't that.
To understand why, look at it from the point of view of a professional magician trying to pay the bills.
I can do card manipulation. I have a card manipulation act that I perform. It is by far the most technically challenging routine that I do and it has literally taken me years to get to the point where I can execute it and perform it. It's closer to juggling than it is to what most magic is (though it's still magic because I'm producing playing cards and fans of playing cards at my fingertips in short sleeves).
Now imagine that the majority of my act was that type of trick. I have bills to pay. I have crowds to entertain TODAY... and if I make just one mistake in a performance, the trick falls flat.
Penn & Teller tip cups & balls because the methods employed in that trick are genuinely entertaining to watch.
And the "let's have the audience lie"... I'm pretty sure you're referencing a segment in their 1990 TV special "Don't Try This at Home" where they had a large semi trailer truck run over Teller while surrounded by an audience who could see how it was done, which they tipped at the end. I wouldn't call that "lazy", I would call that using a medium to convey a message.
Magic doesn't work on television. You need to see it in person to really appreciate that it wasn't done with stooges/actors and camera tricks. That's a thesis that they have carried with them over the years. No one would do that "trick" in any other venue than in a television special. You can't get a big truck up on stage... and if you're doing "instant stooge" type of work, where people on stage from the audience are in on it ... at the risk of getting philosophical, they didn't even experience a magic trick. So it's not so much that the method was "lazy" ... it's that it was completely ineffective, and thus not even a magic trick for a certain group of people. Which was the entire point of the segment.
You're correct about the TV special with the truck. I don't agree that magic doesn't work on TV. Regardless of whether it's a TV show or performed in front of me the nature of magic† (as a performance) is that the performer gets to decide what to show and obviously they aren't going to leave only a single possibility open to explain what I saw, that's something Penn has talked about - there's only one way to do that trick in The Prestige so you would never do that trick.
I've never seen Penn & Teller live, but I have seen Derren Brown both on TV and in person. Now, on TV one of the things which most impresses me is Derren's use of forces. There are a handful that even an amateur who knows what they're looking for can see in some of the TV shows and there are more places where it's obviously a force but I can't figure out how it's done. In person though, that experience is actually less fun, because of course the force doesn't work on me. So he's forced a theatre full of other people to do what he wanted, and they don't know how. It didn't work on me in the TV audience but that's fine, I'm not the target - when it doesn't work in a theatre full of people it's a bit disappointing. When I listened to a recording of "Thou shalt always kill" I knew from the outset what the last two lines would be but that still kinda works, again in person it wouldn't land the same.
† If you claim not to be a magician, that this is real, then it's not up to you what is shown or not shown, if Millikan's drop experiment only worked with this custom made box and a specified oil recipe then it's just a trick. We do the experiment in whatever circumstances are available and it works because it's measuring a fact about our universe, it's not a trick.
I think what you mean by "force" is what magicians call a "psychological force." This is when, through suggestion, the spectator will name or do something that the magician was trying to get them to name/do, while having it look like the spectator had a free choice, through no other means than applied suggestion. These do "work", but as you pointed out they are not sure fire. You get the best results when you can do it on a large group of people and you're upfront about the fact that it won't work for everyone.
Although in Derren Brown's case, one of the things that makes him a genius in the world of magic is that he reversed that dynamic. One of the brilliant things about Derren Brown's "brand" of magic is that by blending stage hypnotism and parlour tricks, he does a lot of things where when you think you're watching a demonstration of stage hypnotism, it's actually a parlour trick that is dressed up to look like stage hypnotism.
In other words, he might use a classic sleight of hand trick to do a "force" while finding a way to frame and present it as if he were using suggestion.
But stage hypnotism and suggestion .. .that's not magic tricks. So if Derren Brown is employing a psychological force, or doing a demonstration of suggestion that will work for the majority of the audience but not all ... that's not a magic trick. By definition, it is not a trick.
What magicians mean when they talk about "forces" are ways to make it look like the spectator, ANY spectator, had a free choice but it was engineered. A card force, for example, where you think you have a free choice of any playing card but the magician "forced" a specific card on you. Those are 100% guaranteed. They don't use suggestion, they use sleight of hand, and there is no person in the world that those don't work 100% of the time on unless the magician makes a mistake.
Back to Derren Brown, although him and Teller are close personal friends and they don't hate each other by any means... P&T have been very outspoken about the fact that they consider some of what Derren does to be unethical, because he presents magic tricks as if they are displays of stage hypnotism or suggestion. Like most "mentalists" he has flirted with a line that many magicians will not cross. Where he claims that by reading body language, or using applied suggestion etc. that he can do or know certain things ... when the reality is those things are executed via traditional parlour trick methods are often just classic magic tricks that most magicians know and can do but are presented with a new/different layer of lies.
So why doesn't magic work on TV ... well, you gave the answer by invoking Derren Brown. If he is doing these "forces" (which to clarify I think you mean psychological "forces") and they work 10 out of 10 times on television but they don't work on 100% of live audience members .. well then you know why magic is weak (at best) on TV ... because all we need to do is go ask 52 people to think of a playing card, and guess that they're thinking of the 7 of Hearts (for example), and then just only air the one take where the guess was right.
There is a YouTube creator named James Hoffman who is a coffee barista. And he was on an episode of Derren Brown's Trick or Treat (if I remember those details correctly). His story of being on that show is very illuminating. He talks about how he was shown 2 different tricks, the first one fried his brain, the second one was "meh." For whatever reason they aired the 2nd one that was "meh", but cut in the reaction to the first one where he was like "OMG OMG that was so amazing."
Why would you trust what magicians tell you, when they say they don't do shit like that on television? This is why, as a huge fan of magic, I kind of hate televised / pre-recorded magic. I have no idea what they did during the editing process. Whereas live, there are so many more restrictions and the audience has a much clearer understanding and impression of what those restrictions are. But on tv... anything is possible through editing and vfx.
Derren used to have a TV show (I don't remember the name) where they actually show some times a live trick that was recorded for the show doesn't work. Because of course it can't always work. It's like those out-takes at the end of a Jackie Chan movie, two hours of this guy being flawless isn't real, here is the time he was a second too slow and ended up taking a kick to the head and his "enemies" all rush over to check he's OK.
I understand the distinction you're making but I think it's so narrow that these overlap in practice, there will always be a psychological element to controlling the volunteer. They could do anything and you don't want that because that's definitely not part of the show.
Derren has also done that "Only show the one where it worked" in a TV show but lampshaded it by also later showing the annoying hours of trying it and failing over and over. Again that's pretty interesting and it's a case where you could just fix it, but where's the fun in that? I think that was on a show about an actual scam pulled on gamblers, where you give somebody the false impression that you're picking winners reliably. That's not a trick, it's just a failure to consider the broader picture - every other participant knows you sometimes pick losers, but one "lucky" person does not and they're the victim.
> I understand the distinction you're making but I think it's so narrow that these overlap in practice
Entire books have been written about this, literally. So obviously we're taking short-cuts in a HN thread. Teller has said "all magic is a psychology experiment" so you're correct in that regard.
The point that I'm trying to make is that magicians rarely take risks in live performances. It is a job and there is a lot at stake. Obviously anything can, and does, happen, but there is a very important reason that magicians (not me, but magicians as a whole) distinguish between "psychological forces" and "forces."
It is that "forces" are considered to be sure fire... so near to 100% guaranteed that we consider them 100% guaranteed. Whereas "psychological forces" are well understood to be much less than 100% guaranteed.
Do magicians ever use psychological forces in practice? Sure. If, when it fails, there is an "out." Where if you saw the same trick performed several times, it would play out slightly differently each time. For example, let's say that I ask you to think of a card, and then I take a 1 in 52 odds guess at what you're thinking just in case I hit. And maybe I will slightly improve my odds by guessing at commonly thought of playing cards. Most of the time it's not going to hit, and that's fine because there's a fall back. But it's done so that in the event that it hits we have what looks like a bonefide miracle. Magicians do that occasionally.
But most of the time it's not that. Most of the time the magician is executing something that is considered to be close enough to 100% that no fallback ("outs" as we call them) is necessary.
Now obviously you could have some jerk physically grab the deck out of your hands or say to you verbally "I want the 8 of spades" when you extend the cards to have them remove one. That can happen, sure, and an experienced performer will be able to navigate the situation and turn it around "you see the thing is, I could guess what card you were thinking of ... 68% of men between the age of 24 and 35 name the 8 of spades ... we need a RANDOM card for this trick" etc. (And that example is valid, but traditional performer wisdom is once you've recovered get that jerk off the stage and move on as fast as possible because they've just proven themselves to be disruptive).
See, I won't say magic can't work on television. It can work, but it does rely on a setting where the home audience can be reasonably sure the film crew is not in cahoots with the performer. This is uncommon, but in some limited scenarios like magic tricks on America's Got Talent, or say P&T's Fool Us there is little reason to cheat with video tricks, as those won't help with the judges/P&T at all, plus you risk having members of the studio audience call out the producers over such trickery.
Things like TV specials on the other hand, yeah not so much.
That's a good point, and P&T have said as much when it comes to Fool Us. That having a live audience was integral to making the show work.
However, as much as I'm a fan of Fool Us, there are things that bother me about the show to the point where I will walk back how I phrased things. It's not that magic "can't work" on TV ... it's that it is always, without exception weaker on TV.
Fool Us is a show made by magicians for magicians (and I'm not even talking about Penn & Teller specifically... I'm talking about Johnny Thompson, Michael Close and others who have worked as producers to make that show what it is) and even they can't always adhere to not cutting during key moments because the nature of television forces them to have to fit varied material during a rigid time block that can change even up to moments before airing.
Then, if you pay attention when watching the show, they use other editing techniques like "risers" for example (a type of subtle sound fx added in post) during the recording which changes it in ways that makes it different than what you would experience if you saw it live.
And then there are still examples of doing stuff for TV with a live audience, that could only be done in that setting.
I'll give you an example of such a trick that has been done on these types of shows numerous times. The first time I saw it performed by Derren Brown on one of his shows I was completely brain-fried.
The trick is that the magician apparently "steals" a spectator's ability to read.
How it looks is that there is a word printed in large bold letters on a piece of paper (in Derren Brown's case it was printed on a page in a magazine). This word is shown to the wider audience and to the camera so that viewers can see it at home. What's great about this trick on TV is that while it is being shown to the selected audience member on stage, the camera can frame it so that viewers at home can verify that they are seeing the same printed word.
And yet while you can read it fine, the spectator on stage sees jibberish.
This trick has been performed on AGT at least once. It's also been performed on Fool Us by a different magician.
It's a marketed trick that you could go buy from a magic shop and perform yourself. But you won't. Why?
Because it works on optical principle that requires lighting to be very controlled.
The creator of that trick even recommends discussing the mechanics of the trick with the film production crew when doing it on television so that the camera operators and the director of photography know how to make it look as good as possible.
In other words... it's a great trick to perform on a sound stage when producing for television. But it doesn't really work that well in other environments. To be fair, you could do it with a live audience in a theatre and there are a lot of stage illusions that need controlled lighting. So it's not like this is something that needs TV specifically, though it kind of still needs cameras to "sell" the illusion so the audience can see what is being shown to the spectator on stage. And magicians love to have philosophical arguments about what constitutes "cheating." You've got magicians like me who think that the audience can't trust TV, and so we're advocates for live entertainment. And then you have magicians who take the position that TV is just another venue, and that the venue is always a tool that is available to be exploited and manipulated because that's what magicians do. But that leaves room for using everything from manipulative editing to cgi.
This is why, in my opinion, while I will walk back what I said a little and rephrase it as "magic is weaker on TV" rather than "can't work", I still think that magic is way more impressive in person... as a result of knowing what's possible on television, even when there is a live in-studio audience.
I've recently done reading "Digital Design and Computer Architecture" by Harris and Harris, and the part about microarchitecture had this exact impression on me: "oh, so we just demux the opcode, enable/disable the necessary signals/paths and it all... just works out in the end, if the clock is fine. Huh. Well, in retrospect it's kinda obvious."
> It's when you take apart a mechanical clock and keep looking for the time-keeping part, until you figure out that there isn't a time-keeping part in there, it's just gears and a spring.
The time-keeping part is arranging gears and a spring in a way that will, in fact, keep time.
> It's when you learn about integrated circuits and full-adders, and keep trying to understand how a bunch of transistors can do Mathematics, until you figure out that there isn't a mathematics-doing part in there, it's just circuits and wires, arranged in a way that makes the voltages come out right.
The mathematics-doing part in there is the arrangement of circuits and wires in ways that can actually do arithmetical operations on voltages.
It's not magic. But an adder, while never more than a bunch of circuits and wires, is still a mathematics-doing part.
Well to be pedantic: the time-keeping part isn’t the gears but a pendulum.
The spring gives energy to the pendulum, but that can’t effect more than in its amplitude: the period of a given pendulum is constant. Later springs demultiply the tick tack of the pendulum into desired units.
The heart of the clock is that choke on energy though a period.
Thats also why the famous phrase: clocks dont measure time but other clocks.
I'm not sure if investors will agree. The general way the stock market works heavily favors shortsighted thinking. They'll say après moi, le déluge and then package the déluge up into sellable financial instruments.
We have to contend with working with people who are sometimes very hard to work with. Watercooler talk gives you the opportunity to remember that the guy who keeps filing badly written tickets has a wife and kids and hobbies, and is likely filing badly written tickets because he's extremely overworked and doesn't have time to write better tickets.
We're social creatures, and having unstructured social interactions greases the wheels when we work together.
I'm sure this also depends on the kind of organization you work at, but I find that being on-site makes a huge difference. Yes, even in the quality of the work.
That's like saying "the imp you summoned and are keeping in a cage won't always tell the truth" or "fever dreams won't always be true prophecies of things to come".
I'd like to thank you for the time and effort it must take to research, write and edit these articles. The tone you strike with these articles is a delight to read, and I find myself gobbling these things up even for topics about which I (falsely, it usually turns out) consider myself fairly knowledgeable.
As a compiler guy, I'd appreciate some look at the layers of abstraction in-between (so, ASM).
Microbenchmarks are famously jittery on modern CPUs due to cache effects, branch prediction, process eviction, data dependencies, pipeline stalls, OoO execution, instruction level parallelism, etc.
You have to be really careful to ensure the numbers you're getting are really coming from the thing you're trying to benchmark, and aren't corrupted beyond recognition by your benchmarking harness.
Some of these questions would surely be trivial if I actually knew any Go, but I'm left wondering:
* What does the machine code / assembly look like for this? What does the cast compile down to?
* What's `int` an alias for? I assume 64-bit-signed-integer?
* Are integer casts checked in go? Would an overflowing cast fault?
I for one develop on GCC-Go. The only reason I chose Go as my next project's language is because it has a GCC implementation (I have strict rule about GPL licensed development tool chains for my own projects).
As far as I can see, GCCGo implements Go 1.18 as of today [0]. Moreover, as noted on official Golang webpage for GCCGo [1], there are even some advantages for using GCCGo, quoting:
"On x86 GNU/Linux systems the gccgo compiler is able to use a small discontiguous stack for goroutines. This permits programs to run many more goroutines, since each goroutine can use a relatively small stack. Doing this requires using the gold linker version 2.22 or later. You can either install GNU binutils 2.22 or later, or you can build gold yourself."
Considering GCC can optimize well written code to the point of saturating the target processor, given the correct target flags, I'm not entirely sure that "gc" would be "much" faster than GCCGo. I'm relatively new with Go, but equally old with GCC, esp. with g++, so assuming the optimization prowess is equally valid for GCCGo.
Last but not least, GCCGo is a part of GCC as a primary language since 4.7, which is an eternity in software terms.
Doesn't look like it, since you mention Go compiler being faster, which is true and isn't the point of generated machine code, as the reference compiler doesn't do many of the GCC optimization passes.
All are good points. Also, loop unrolling and induction variable analysis. LLVM is particularly aggressive at trying to optimize inductions. It will literally turn a "sum of i from 0 to N" into "n(n+1)/2", among others.
It's really important to look at the actual machine code.
> It will literally turn a "sum of i from 0 to N" into "n(n+1)/2", among others[1]
Yeah, seen that on a godbolt youtube vid. Question is, should it do this? Or should it force you to use a library, by reporting what you're trying to do and telling you there's an easier way ( "sum of 1 to n is <formula>, instead of a loop use library function 'sum1toN()" )
I think getting too clever risks hurting the user by not letting them know there's a better way.
[1] actually it seems to do a slightly different version of this to prevent risk of overflow, but same result.
One issue is that an optimization like this could have resulted from many prior inlinings and foldings that had to work together to create the pattern that was finally matched, so it's not obvious to point the user to what they should change their code to. Maybe they actually intended that the code get folded at the end by the compiler, but all of those optimizations were done by templates that will get folded a different, but equally cool way, under different specializations.
Generally I think some of LLVM's optimizations are trying too hard for the amount of complexity and compilation overhead they create. All that complexity comes at the risk of bugs. With optimizations around UB, it becomes downright mind-boggling what could go wrong. But I'm not an LLVM maintainer so what the heck do I know.
micro benchmarks are especially problematic in real-world code where you load stuff from random addresses in memory.
If the code after the cast is blocked on a memory load, then you have a lot of free instructions while the cpu is waiting for the memory load to complete. In this case it doesn't matter if the cast is free or takes a handfull of instructions.
Sometimes code becomes faster by using more instructions to make the data more compact so more of the data stays in the caches.
Microbenchmarks are only valid for the one function under test, and only on the current machine; they're all right for optimizing on particular hardware, but not so much to go out into the world and go "X is faster than Y"
That said, I did like this website where you could set up JS benchmarks, they would run on your own machine and you could compare how it ran on other people's systems. It wasn't perfect, but it gave a decent indication if X was faster than Y. Of course, it's a snapshot in time, JS engines have gone through tons of optimizations over the years.