ID:2416249
 
I wanted to test the performance impact of declaring vars, so I wrote this test case:

https://cdn.discordapp.com/attachments/245876940274139166/ 522943745876951045/unknown.png

and profiled it:

https://cdn.discordapp.com/attachments/245876940274139166/ 522943795034324992/unknown.png

I was puzzled:
- Unused variables are clearly not optimized out, but this is fine because a warning is emitted and it's up to the programmer to fix the issue;
- /client/verb/meme consumes the bulk of the Self CPU time, but it's doing nothing different than what /client/verb/epic is doing.

To dig further I devised another test case:

https://media.discordapp.net/attachments/245876940274139166/ 522950230610673668/unknown.png?width=896&height=398

and profiled it:

https://media.discordapp.net/attachments/245876940274139166/ 522950305046855698/unknown.png

To explain what's going on:
- I have 5 verbs that call 5 different procs in a loop a fixed amount of times
- The verbs and procs are ordered so that meme1 has the most number of vars and meme5 has no vars at all.

The profiler output shows that the CPU cost of the called procs is not correlated with the number of vars contained within.
Instead, the CPU cost of declaring variables is counted towards the CALLER of the proc.

So my questions:
- Why is this the case?
- Is this behavior exclusive to declaring and/or "cleaning up" proc variables?
- Is it a problem? Should it be changed?
This has been observed before, you can actually get around it by using call()() (the time then ends up being not counted), but yes, setup and breakdown seem to count to the caller, as does the work for handling arguments.

This is technically a bug that could be reported