Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Search - "234"
-
So recently I did a lot of research into the internals of Computers and CPUs.
And i'd like to share a result of mine.
First of all, take some time to look at the code down below. You see two assembler codes and two command lines.
The Assembler code is designed to test how the instructions "enter" and "leave" compare to manually doing what they are shortened to.
Enter and leave create a new Stackframe: this means, that they create a new temporary stack. The stack is where local variables are put to by the compiler. On the right side, you can see how I create my own stack by using
push rbp
mov rbp, rsp
sub rsp, 0
(I won't get into details behind why that works).
Okay. Why is this even relevant?
Well: there is the assumption that enter and leave are very slow. This is due to raw numbers:
In some paper I saw ( I couldn't find the link, i'm sorry), enter was said to use up 12 CPU cycles, while the manual stacking would require 3 (push + mov + sub => 1 + 1 + 1).
When I compile an empty function, I get pretty much what you'd expect just from the raw numbers of CPU cycles.
HOWEVER, then I add the dummy code in the middle:
mov eax, 123
add eax, 123543
mov ebx, 234
div ebx
and magically - both sides have the same result.
Why????
For one thing, there is CPU prefetching. This is the CPU loading in ram before its done executing the current instruction (this is how anti-debugger code works, btw. Might make another rant on that). Then there is the fact that the CPU usually starts work on the next instruction while the current instruction is processing IFF the register currently involved isnt involved in the next instruction (that would cause a lot of synchronisation problems). Now notice, that the CPU can't do any of that when manually entering and leaving. It can only start doing the mov eax, 1234 while performing the sub rsp, 0.
----------------
NOW: notice that the code on the right didn't take any precautions like making sure that the stack is big enough. If you sub too much stack at once, the stack will be exhausted, thats what we call a stack overflow. enter implements checks for that, and emits an interrupt if there is a SO (take this with a grain of salt, I couldn't find a resource backing this up). There are another type of checks I don't fully get (stack level checks) so I'd rather not make a fool of myself by writing about them.
Because of all those reasons I think that compilers should start using enter and leave again.
========
This post showed very well that bare numbers can often mislead.21 -
When you've been coding for what seems like an hour and when you finally look up it's dark outside 😛
-
FFS stop squashing commits. If “updated comments” is what the commit was it should show it in git blame. If “fixed null check” is what the commit was it should show it in git blame.
There is no reason to have “ticket-234 service revision” beside 1000 lines of code. How does anyone justify this loss of git info for the sake of “clean history”? Nobody looks at your history and says, “That is bloody clean git history I should write home about it.” People do however look at the code and say, “I wish I knew WTF they were trying to do on that line.”16 -
My girl friend was complaining that I care more about programming than her.
I told her,
"Trust me baby, in the array of my interests you are [1]."
She was satisfied.3 -
Called to maintain a WordPress site. Site has 100 plugins, two to disable right click. Somebody kill me already 😂😂😂1
-
I think the reason most people hate frontend these days can be summed up by the fact that the frontend of my fairly simple React webapp is about 850 loc while the entire Express and MongoDB server is a mere 234 loc
God damn frontend is a lot of work these days6 -
So I wanted to merge some variables that actually had the same roles.
So I did the Replace in all files (why I didn't refactor, I dunno).
Expected 10 changements, got 234.
Woops. -
spend better part of my day processing about 400M rows of data with MySql, woo ain't no single line of code that can do that in 12hrs 😊
-
Going to design a contract for my services it's going to include additional costs for additional changes because with clients the job is never done 😉😉3
-
I finally attempted php, I wrote a bunch of scripts to fetch data... I feel like I have betrayed myself 😞😞😞
I should have just absorbed the cost of azure 😭😭😭 now am a php dev.... The things I'm about to do, the horrors I'm about to put out into the world.... Pulling your hair out will be the least of your worries, dear maintainer forgive us all, always and forever. 😳1 -
A toast to the perks of backend, to never being bothered again with every single ui change.... Just you and your code 😏😀2
-
instagrams "based on likes" is total bullshit, I don't like shit those suggestions like but if you scroll through your contacts you'll find those suggestions. Why not just say it like it is: "from your contacts or from your friends contacts"3
-
By starting the company I think I just dissolved, perfect opportunity to start a new one... Software company name suggestions anyone3
-
and so today almost an hour ago I became the left one... I guess she went with the right one 😂😂😂... How many days have passed between my previous "relationship" post and this one ending... but in truth I was in the "babe" zone 😂😂😂
On to the next one, with the lessons from mistakes of the previous, hopefully she will last longer 🙏1 -
Project manager, knows nothing/little about the project... Always sends new features to be added only to be removed 1hr later 😣😣, you have experienced nothing until you work under 1
-
I once wrote a whole lot of classes with lots of functions and pushed them to the live server without testing... There were no errors 😎1
-
when you are using javascript frameworks and plugins in mvc and you have ReSharper, for your own safety and sanity exclude *.js