Why do compilers remove dead code? (Why is it worth it?)
up vote
-2
down vote
favorite
By dead code, I mean some reachable code that has no impact of the result (except time or space requirements).
I understand that dead code elimination might improve app performance. I can understand even some theoretical examples. But even after considering inlining, it looks like this should be rarely an issue. Overall, it looks like there is much effort for something with a little effect. It suggests using such an effort for some other optimizations could bring more value.
Maybe I have overseen some reason why dead code occurs and maybe someone will be able to show realistic examples of dead code.
Or maybe dead code elimination is rather a byproduct of some other optimizations. (In other words, there are some other optimizations analyzing code flow, so that dead code elimination is quite easy to implement.)
P.S.: I know, this question is a bit on the edge of opinion-based questions. I believe this question is OK, because one can point to some evidence, e.g., on some realistic code where DCE helps or to some kind of optimization that helps with implementation of dead code elimination.
optimization compiler-optimization dead-code
|
show 2 more comments
up vote
-2
down vote
favorite
By dead code, I mean some reachable code that has no impact of the result (except time or space requirements).
I understand that dead code elimination might improve app performance. I can understand even some theoretical examples. But even after considering inlining, it looks like this should be rarely an issue. Overall, it looks like there is much effort for something with a little effect. It suggests using such an effort for some other optimizations could bring more value.
Maybe I have overseen some reason why dead code occurs and maybe someone will be able to show realistic examples of dead code.
Or maybe dead code elimination is rather a byproduct of some other optimizations. (In other words, there are some other optimizations analyzing code flow, so that dead code elimination is quite easy to implement.)
P.S.: I know, this question is a bit on the edge of opinion-based questions. I believe this question is OK, because one can point to some evidence, e.g., on some realistic code where DCE helps or to some kind of optimization that helps with implementation of dead code elimination.
optimization compiler-optimization dead-code
2
If the code has no effect, why keep it? A single location that has useless code may not appear to have much of an effect, but removing all useless code from all programs as a standard policy will likely have a definite performance impact in both speed and memory for the overall system. It's a good default policy.
– Ryan Pierce Williams
Nov 11 at 11:20
@RyanPierceWilliams Sure, it is good to use it when it is implemented. I just doubt it is a common issue. Imagine you are involved in compiler development. You are about to decide if your team will spend time of this optimization or on some other kind of optimization. And someone like me objects: DCE has a little effect and it is a theoretical issue. Other optimizations will have deeper effect. How would you advocate spending the time on DCE?
– v6ak
Nov 11 at 11:27
1
it saves disk space and ram and startup time and makes the cpu prefetcher's job easier..
– hanshenrik
Nov 11 at 11:28
@v6ak You need to pick and choose your battles of course. If there are other areas to improve that will provide you with greater performance returns then do those first.
– Ryan Pierce Williams
Nov 11 at 11:29
1
@hanshenrik The OP is not asking whether DCE is useful, the question perhaps can be stated more clearly as "how significant is the performance improvement gained from DCE relative to other compiler optimizations when applied on real programs?" Also, regarding your comment, I don't see how it can make the CPU instruction prefetcher easier (I think you're talking about the instruction cache prefetcher). Also, saving disk space, while true, is not really the most important benefit of DCE. Saving startup time is also not necessarily true. Wikipedia has a very brief but good intro to DCE.
– Hadi Brais
Nov 13 at 0:01
|
show 2 more comments
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
By dead code, I mean some reachable code that has no impact of the result (except time or space requirements).
I understand that dead code elimination might improve app performance. I can understand even some theoretical examples. But even after considering inlining, it looks like this should be rarely an issue. Overall, it looks like there is much effort for something with a little effect. It suggests using such an effort for some other optimizations could bring more value.
Maybe I have overseen some reason why dead code occurs and maybe someone will be able to show realistic examples of dead code.
Or maybe dead code elimination is rather a byproduct of some other optimizations. (In other words, there are some other optimizations analyzing code flow, so that dead code elimination is quite easy to implement.)
P.S.: I know, this question is a bit on the edge of opinion-based questions. I believe this question is OK, because one can point to some evidence, e.g., on some realistic code where DCE helps or to some kind of optimization that helps with implementation of dead code elimination.
optimization compiler-optimization dead-code
By dead code, I mean some reachable code that has no impact of the result (except time or space requirements).
I understand that dead code elimination might improve app performance. I can understand even some theoretical examples. But even after considering inlining, it looks like this should be rarely an issue. Overall, it looks like there is much effort for something with a little effect. It suggests using such an effort for some other optimizations could bring more value.
Maybe I have overseen some reason why dead code occurs and maybe someone will be able to show realistic examples of dead code.
Or maybe dead code elimination is rather a byproduct of some other optimizations. (In other words, there are some other optimizations analyzing code flow, so that dead code elimination is quite easy to implement.)
P.S.: I know, this question is a bit on the edge of opinion-based questions. I believe this question is OK, because one can point to some evidence, e.g., on some realistic code where DCE helps or to some kind of optimization that helps with implementation of dead code elimination.
optimization compiler-optimization dead-code
optimization compiler-optimization dead-code
asked Nov 11 at 11:16
v6ak
1,25821024
1,25821024
2
If the code has no effect, why keep it? A single location that has useless code may not appear to have much of an effect, but removing all useless code from all programs as a standard policy will likely have a definite performance impact in both speed and memory for the overall system. It's a good default policy.
– Ryan Pierce Williams
Nov 11 at 11:20
@RyanPierceWilliams Sure, it is good to use it when it is implemented. I just doubt it is a common issue. Imagine you are involved in compiler development. You are about to decide if your team will spend time of this optimization or on some other kind of optimization. And someone like me objects: DCE has a little effect and it is a theoretical issue. Other optimizations will have deeper effect. How would you advocate spending the time on DCE?
– v6ak
Nov 11 at 11:27
1
it saves disk space and ram and startup time and makes the cpu prefetcher's job easier..
– hanshenrik
Nov 11 at 11:28
@v6ak You need to pick and choose your battles of course. If there are other areas to improve that will provide you with greater performance returns then do those first.
– Ryan Pierce Williams
Nov 11 at 11:29
1
@hanshenrik The OP is not asking whether DCE is useful, the question perhaps can be stated more clearly as "how significant is the performance improvement gained from DCE relative to other compiler optimizations when applied on real programs?" Also, regarding your comment, I don't see how it can make the CPU instruction prefetcher easier (I think you're talking about the instruction cache prefetcher). Also, saving disk space, while true, is not really the most important benefit of DCE. Saving startup time is also not necessarily true. Wikipedia has a very brief but good intro to DCE.
– Hadi Brais
Nov 13 at 0:01
|
show 2 more comments
2
If the code has no effect, why keep it? A single location that has useless code may not appear to have much of an effect, but removing all useless code from all programs as a standard policy will likely have a definite performance impact in both speed and memory for the overall system. It's a good default policy.
– Ryan Pierce Williams
Nov 11 at 11:20
@RyanPierceWilliams Sure, it is good to use it when it is implemented. I just doubt it is a common issue. Imagine you are involved in compiler development. You are about to decide if your team will spend time of this optimization or on some other kind of optimization. And someone like me objects: DCE has a little effect and it is a theoretical issue. Other optimizations will have deeper effect. How would you advocate spending the time on DCE?
– v6ak
Nov 11 at 11:27
1
it saves disk space and ram and startup time and makes the cpu prefetcher's job easier..
– hanshenrik
Nov 11 at 11:28
@v6ak You need to pick and choose your battles of course. If there are other areas to improve that will provide you with greater performance returns then do those first.
– Ryan Pierce Williams
Nov 11 at 11:29
1
@hanshenrik The OP is not asking whether DCE is useful, the question perhaps can be stated more clearly as "how significant is the performance improvement gained from DCE relative to other compiler optimizations when applied on real programs?" Also, regarding your comment, I don't see how it can make the CPU instruction prefetcher easier (I think you're talking about the instruction cache prefetcher). Also, saving disk space, while true, is not really the most important benefit of DCE. Saving startup time is also not necessarily true. Wikipedia has a very brief but good intro to DCE.
– Hadi Brais
Nov 13 at 0:01
2
2
If the code has no effect, why keep it? A single location that has useless code may not appear to have much of an effect, but removing all useless code from all programs as a standard policy will likely have a definite performance impact in both speed and memory for the overall system. It's a good default policy.
– Ryan Pierce Williams
Nov 11 at 11:20
If the code has no effect, why keep it? A single location that has useless code may not appear to have much of an effect, but removing all useless code from all programs as a standard policy will likely have a definite performance impact in both speed and memory for the overall system. It's a good default policy.
– Ryan Pierce Williams
Nov 11 at 11:20
@RyanPierceWilliams Sure, it is good to use it when it is implemented. I just doubt it is a common issue. Imagine you are involved in compiler development. You are about to decide if your team will spend time of this optimization or on some other kind of optimization. And someone like me objects: DCE has a little effect and it is a theoretical issue. Other optimizations will have deeper effect. How would you advocate spending the time on DCE?
– v6ak
Nov 11 at 11:27
@RyanPierceWilliams Sure, it is good to use it when it is implemented. I just doubt it is a common issue. Imagine you are involved in compiler development. You are about to decide if your team will spend time of this optimization or on some other kind of optimization. And someone like me objects: DCE has a little effect and it is a theoretical issue. Other optimizations will have deeper effect. How would you advocate spending the time on DCE?
– v6ak
Nov 11 at 11:27
1
1
it saves disk space and ram and startup time and makes the cpu prefetcher's job easier..
– hanshenrik
Nov 11 at 11:28
it saves disk space and ram and startup time and makes the cpu prefetcher's job easier..
– hanshenrik
Nov 11 at 11:28
@v6ak You need to pick and choose your battles of course. If there are other areas to improve that will provide you with greater performance returns then do those first.
– Ryan Pierce Williams
Nov 11 at 11:29
@v6ak You need to pick and choose your battles of course. If there are other areas to improve that will provide you with greater performance returns then do those first.
– Ryan Pierce Williams
Nov 11 at 11:29
1
1
@hanshenrik The OP is not asking whether DCE is useful, the question perhaps can be stated more clearly as "how significant is the performance improvement gained from DCE relative to other compiler optimizations when applied on real programs?" Also, regarding your comment, I don't see how it can make the CPU instruction prefetcher easier (I think you're talking about the instruction cache prefetcher). Also, saving disk space, while true, is not really the most important benefit of DCE. Saving startup time is also not necessarily true. Wikipedia has a very brief but good intro to DCE.
– Hadi Brais
Nov 13 at 0:01
@hanshenrik The OP is not asking whether DCE is useful, the question perhaps can be stated more clearly as "how significant is the performance improvement gained from DCE relative to other compiler optimizations when applied on real programs?" Also, regarding your comment, I don't see how it can make the CPU instruction prefetcher easier (I think you're talking about the instruction cache prefetcher). Also, saving disk space, while true, is not really the most important benefit of DCE. Saving startup time is also not necessarily true. Wikipedia has a very brief but good intro to DCE.
– Hadi Brais
Nov 13 at 0:01
|
show 2 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248175%2fwhy-do-compilers-remove-dead-code-why-is-it-worth-it%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
If the code has no effect, why keep it? A single location that has useless code may not appear to have much of an effect, but removing all useless code from all programs as a standard policy will likely have a definite performance impact in both speed and memory for the overall system. It's a good default policy.
– Ryan Pierce Williams
Nov 11 at 11:20
@RyanPierceWilliams Sure, it is good to use it when it is implemented. I just doubt it is a common issue. Imagine you are involved in compiler development. You are about to decide if your team will spend time of this optimization or on some other kind of optimization. And someone like me objects: DCE has a little effect and it is a theoretical issue. Other optimizations will have deeper effect. How would you advocate spending the time on DCE?
– v6ak
Nov 11 at 11:27
1
it saves disk space and ram and startup time and makes the cpu prefetcher's job easier..
– hanshenrik
Nov 11 at 11:28
@v6ak You need to pick and choose your battles of course. If there are other areas to improve that will provide you with greater performance returns then do those first.
– Ryan Pierce Williams
Nov 11 at 11:29
1
@hanshenrik The OP is not asking whether DCE is useful, the question perhaps can be stated more clearly as "how significant is the performance improvement gained from DCE relative to other compiler optimizations when applied on real programs?" Also, regarding your comment, I don't see how it can make the CPU instruction prefetcher easier (I think you're talking about the instruction cache prefetcher). Also, saving disk space, while true, is not really the most important benefit of DCE. Saving startup time is also not necessarily true. Wikipedia has a very brief but good intro to DCE.
– Hadi Brais
Nov 13 at 0:01