Just to be clear, what does default() do that makes the code change?
And is removing it, changes any behaviour in the sample code? Is it redundant and I just seeing a side effect of it in the outputted assemenly?
Default assigns a value to the (entire) record.
- In this case the value is zero / nil.
- In this case the record and the field in it are the same thing (so the record could have padding)
So in this case it does the same change as the ":= nil" => but it may use different assembler code. And that may mean the code occupies a different count of bytes. And subsequent code gets shifted. => changing alignment (in this case of the loop) => having effects on how fast it runs.
Your CPU does a lot more than you expect.
"mov rax, [address]" (move data between mem and register)
The CPU produces a whole program from that. So called micro-ops. And those get executed. That translation can be cached. And that can have an effect on the speed.
But caching at bounds is not all.
Sometimes a list of steps can be changed in order, still meaning the same (e.g. "A:=1; b:=2;" can be swapped). That also happens sometimes with conditions and other specific ops.
Depending on the order, the speed may differ (And no, don't try to reorder your Pascal code => that wont do no good.
This is about the assembler level. You can't affect that)
Because, if in the correct order, your CPU can do them in parallel. But only if in the correct order.
And there are way more things affecting speed.
What you can affect, is in which order to access data in memory. And this can have an impact on cache usage (data/memory cache).
And looking at algorithms used: Keyword "Big O"
Then again => Is that code actually worth the optimization?
How often is it called? How much percentage time of your app does it take? If you speed it up by 5% (in real life, not in an artificial benchmark), how much does your app gain?
Because lets pretend that code makes it to 10% of the runtime of your app. And you speed it up by 5% => Your app will be only 0.5% faster.