469,090 Members | 1,203 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,090 developers. It's quick & easy.

.NET Compiler optimization and component updates

All,

This is a general question regarding how, and if, compiler optimization
techniques affect the general concept of being able to update a component of
an application without requiring a recompile of client code.

For example, suppose I have component: common.dll which defines several
constant values, say Const_A, Const_B and Const_C. Further say I have some
client code in another component: client.dll which references common.dll and
the constants defined within it. If I redefine the values of the constant
values and redeploy common.dll, will client.dll use the new values?

I encountered a situation like this in which client.dll did not use the
redefined constant values until I recompiled client.dll against the newer
version of common.dll.

I expect the compiler inlines the constant values for optimization, but does
this in someway break the concept of being able to modify and redeploy server
components without having to recompile client code? Also, what happens when
the compiler uses other optimization techniques like function inlining?

I guess my real question is when do I know it's safe to just redeploy
client.dll without needing to recompile client.dll?

I'm certainly not an expert in compiler construction or optimization so any
insight is appreciated.

Thanks,
Nick
Jul 21 '05 #1
3 3056
Nick L. <Ni***@discussions.microsoft.com> wrote:
This is a general question regarding how, and if, compiler optimization
techniques affect the general concept of being able to update a component of
an application without requiring a recompile of client code.

For example, suppose I have component: common.dll which defines several
constant values, say Const_A, Const_B and Const_C. Further say I have some
client code in another component: client.dll which references common.dll and
the constants defined within it. If I redefine the values of the constant
values and redeploy common.dll, will client.dll use the new values?
If they're truly constants, declared as constants rather than static
readonly values, then it'll use the old values.
I encountered a situation like this in which client.dll did not use the
redefined constant values until I recompiled client.dll against the newer
version of common.dll.
Yup.
I expect the compiler inlines the constant values for optimization, but does
this in someway break the concept of being able to modify and redeploy server
components without having to recompile client code? Also, what happens when
the compiler uses other optimization techniques like function inlining?
Inlining is done by the JIT compiler, not the language -> IL compiler.
I guess my real question is when do I know it's safe to just redeploy
client.dll without needing to recompile client.dll?


Even in times when it's *safe* to redeploy just the library without
redeploying things compiled against it, I believe it would be *better*
to recompile everything. From what I remember about the file format,
there are "hints" in the file to say where methods in other assemblies
are likely to be, etc. It should work if they've changed location, but
slightly slower.

You should always recompile to check that the interfaces etc haven't
changed in an incompatible way, of course, but the choice of whether or
not to then redeploy is a tricky one. The interfaces may have changed
in a source-compatible but not binary-compatible way (eg you may have
changed a method from Foo(string s) to Foo(object o), and everything
will still recompile, but old programs will fail to link at runtime).
Then there's the constants problem you brought up.

I think things are slightly worse in the compact framework - I believe
there's a stronger tie there, and you *have* to recompile the
assemblies which depend on the changed assembly. (I've certainly seen
things fail for no good reason if that's not the case.)

As you can tell, I'm pretty conservative about this kind of thing,
myself...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
Thanks Jon, I appreciate your feedback; it has been very helpful.

"Jon Skeet [C# MVP]" wrote:
Nick L. <Ni***@discussions.microsoft.com> wrote:
This is a general question regarding how, and if, compiler optimization
techniques affect the general concept of being able to update a component of
an application without requiring a recompile of client code.

For example, suppose I have component: common.dll which defines several
constant values, say Const_A, Const_B and Const_C. Further say I have some
client code in another component: client.dll which references common.dll and
the constants defined within it. If I redefine the values of the constant
values and redeploy common.dll, will client.dll use the new values?


If they're truly constants, declared as constants rather than static
readonly values, then it'll use the old values.
I encountered a situation like this in which client.dll did not use the
redefined constant values until I recompiled client.dll against the newer
version of common.dll.


Yup.
I expect the compiler inlines the constant values for optimization, but does
this in someway break the concept of being able to modify and redeploy server
components without having to recompile client code? Also, what happens when
the compiler uses other optimization techniques like function inlining?


Inlining is done by the JIT compiler, not the language -> IL compiler.
I guess my real question is when do I know it's safe to just redeploy
client.dll without needing to recompile client.dll?


Even in times when it's *safe* to redeploy just the library without
redeploying things compiled against it, I believe it would be *better*
to recompile everything. From what I remember about the file format,
there are "hints" in the file to say where methods in other assemblies
are likely to be, etc. It should work if they've changed location, but
slightly slower.

You should always recompile to check that the interfaces etc haven't
changed in an incompatible way, of course, but the choice of whether or
not to then redeploy is a tricky one. The interfaces may have changed
in a source-compatible but not binary-compatible way (eg you may have
changed a method from Foo(string s) to Foo(object o), and everything
will still recompile, but old programs will fail to link at runtime).
Then there's the constants problem you brought up.

I think things are slightly worse in the compact framework - I believe
there's a stronger tie there, and you *have* to recompile the
assemblies which depend on the changed assembly. (I've certainly seen
things fail for no good reason if that's not the case.)

As you can tell, I'm pretty conservative about this kind of thing,
myself...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #3
"Nick L." <Ni***@discussions.microsoft.com> wrote in
news:53**********************************@microsof t.com...
All,

This is a general question regarding how, and if, compiler optimization
techniques affect the general concept of being able to update a component
of
an application without requiring a recompile of client code.

For example, suppose I have component: common.dll which defines several
constant values, say Const_A, Const_B and Const_C. Further say I have some
client code in another component: client.dll which references common.dll
and
the constants defined within it. If I redefine the values of the constant
values and redeploy common.dll, will client.dll use the new values?
Keep in mind that C# code will be compiled to IL code at compile time (by
the C# compiler), and IL will be compiled to native code at runtime (by the
JIT):
Now, there is no representation for constants in IL code - the C# compiler
already translates them to their values.
I encountered a situation like this in which client.dll did not use the
redefined constant values until I recompiled client.dll against the newer
version of common.dll.

I expect the compiler inlines the constant values for optimization, but
does
this in someway break the concept of being able to modify and redeploy
server
components without having to recompile client code? Also, what happens
when
the compiler uses other optimization techniques like function inlining?
Function inlining is done by the JIT, so this won't break anything.
I guess my real question is when do I know it's safe to just redeploy
client.dll without needing to recompile client.dll?


This is more a rule of thumb: You can usually safely change private members
(unless you use binary serialization), change code (see below), and add new
members. AFAIK this is more or less the strategy MS uses for updates and
service packs.

Note that "you don't have to recompile" doesn't mean "you don't have to
re-test": Changing a method can *always* break client code if you change
pre- or postconditions, throw new exceptions or whatever. But doing this can
break client code if you recompile it, too.

Niki
Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Stephan Diehl | last post: by
14 posts views Thread by joshc | last post: by
3 posts views Thread by gabe | last post: by
5 posts views Thread by wkaras | last post: by
30 posts views Thread by lovecreatesbea... | last post: by
29 posts views Thread by sammy | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by kglaser89 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.