Closed Bug 944581 Opened 11 years ago Closed 11 years ago

Would it be possible to optimize constant conditionals?

Categories

(Core :: JavaScript Engine: JIT, defect)

25 Branch
x86_64
Windows 7
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 911293

People

(Reporter: warcraftthreeft, Unassigned)

Details

User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0 (Beta/Release) Build ID: 20131112160018 Steps to reproduce: Currently the Javascript engine in Firefox can remove code that it determines will never be executed. As an example: if (false) { // Tons of stuff } That code will never be executed and the engine is smart enough to remove it. Firefox has support for the "const" keyword in Javascript but doesn't evaluate conditionals that use it. As an example: http://jsfiddle.net/9LCra/ // Debug Off Control { console.time("benchmark control"); for (var i = 0; i < 10000000; ++i) { } console.timeEnd("benchmark control"); } // Debug Off { const debugOff = false; var debugOffCounter = 0; console.time("benchmark debug off"); for (var i = 0; i < 10000000; ++i) { if (debugOff) { debugOffCounter++; } } console.timeEnd("benchmark debug off"); } // Debug On { const debugOn = true; var debugOnCounter = 0; console.time("benchmark debug on"); for (var i = 0; i < 10000000; ++i) { if (debugOn) { debugOnCounter++; } } console.timeEnd("benchmark debug on"); } Actual results: The first two blocks have a different run-time performance. Expected results: One would expect the first two code blocks to execute at the same time since "if (debugOff)" should be looked at identically as "if (false)" but it currently isn't. This is a useful property to have for easily removing huge chunks of debug code from libraries without having to generate two separate Javascript files or maintain preprocessor scripts. This is more of an optimization request than a bug, but I imagine const optimizations like this would be useful in a few places.
Thanks for filling this well detailed bug. This is a known issue which should be easy to fix. See Bug 911293.
Status: UNCONFIRMED → RESOLVED
Closed: 11 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.