C # optimization and side effects

Can optimizations performed by a C # compiler or JITter have visible side effects?

One example that I disabled.

var x = new Something();
A(x);
B(x);

When called, A(x) xstorage at the end Ais guaranteed - because it Buses the same parameter. But if Bdefined as

public void B(Something x) { }

It B(x)can then be fixed by the optimizer, and a call may be required instead GC.KeepAlive(x).

Can this optimization be performed by JITter?

Are there other optimizations that may have visible side effects besides stack trace changes?

+5
source share
4 answers

A (x) x A - B .

. , A . , B , x . , A x; , , , x . , ; , .


( , , ), JITter?

, . .

3.9 , :

, , , . # , . , , , , , ( ) , .


, # JITter, ?

3.10 , :

# .

, , .

, , , .

# , :

. , , .

.

.

, , , ( , ).

(, , ), , .

- - , ; , - , ? , .

, . .

, . , " ", " ".

+6

B x, x .

, , , .

+8

B . :

var x = new Something();
A(x);

, A(x) , A(x) x, x , A. , , , A . , JITER ( ), x.

, " ". , JITer, , , , . ""? "?"

0

Eric Lippert has launched an excellent refactoring series that leads me to believe that the C # compiler and JITter should not introduce side effects. Part 1 and Part 2 are currently online.

0
source

All Articles