Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This answer is purely speculative -- but I suspect that the answer has 3 parts.</p> <p>1: The code transforms to prefer Dup over local variables is very non-trivial, even when you ignore side effects. It adds a lot of complexity and potentially a lot of execution time to the optimization.</p> <p>2: You can't ignore side effects. In the example where everything is just a literal, it is very easy to know that the values are in stack or locals, and are therefore under complete control of the current instructions. Once those values come from the heap, static memory, or method calls, you can no longer shuffle things around to use Dup instead of locals. Changing the order may change how things actually work, and cause unintended consequences due to side effects or external access to shared memory. This means that usually, you can't make these optimizations.</p> <p>3: The assumption that stack values are faster that local variables is not a good assumption -- it may be true for a particular IL->machine code transform that stack values are faster, but there is no reason why a smart JIT would not put a stack location into memory and a local variable into a register. It is the JIT's job to know what is fast and what is slow for the current machine, and it is the JIT's job to solve the problem. By design, the CIL compiler does not have an answer to whether locals or stack are faster; and so the measurable difference between these results is only in code size.</p> <p>Put together, 1 means that it is hard and has a non-trivial cost, 2 means that real world cases where it would be valuable are few, and 3 means that 1 and 2 are irrelevant anyways. </p> <p>Even if the goal is to minimize CIL size, which IS a measurable goal for the CIL compiler, reason #2 describes this as a small improvement to a small amount of cases. The Pareto principle can't tell us that it is a BAD idea to implement this kind of optimization, but it will recommend that there are probably BETTER uses of developer time.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload