bugzilla.mozilla.org has resumed normal operation. Attachments prior to 2014 will be unavailable for a few days. This is tracked in Bug 1475801.
Please report any other irregularities here.

Odinmonkey, IM: Poor handling of sequence of ifs equivalent to a switch statement

REOPENED
Unassigned

Status

()

Core
JavaScript Engine
--
enhancement
REOPENED
5 years ago
2 months ago

People

(Reporter: Marc Feeley, Unassigned)

Tracking

21 Branch
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

5 years ago
Created attachment 763371 [details]
Test program

A sequence of ifs testing a single variable for a set of values, semantically equivalent to a "switch", is not optimized.  For the test program the performance is 20x slower than v8 which seems to optimize this case:

% /usr/bin/time js switch-opt1.js
start = 0
end sum=200000000
       61.19 real        61.16 user         0.00 sys

% /usr/bin/time d8 switch-opt1.js
start = 0
end sum=200000000
        3.33 real         3.31 user         0.00 sys

This was discovered while experimenting with emscripten which (sometimes?) translates the C switch statement into a sequence of ifs.  While that issue may be resolved by improving emscripten, it is a style of code that might arise in some other settings (automatically generated code, naive programmers, macros?) so it is worthwhile detecting this pattern and handling it as efficiently as a switch statement.
I guess we might want to optimize this in IM, too, but Odinmonky is probably more pressing.
OS: Mac OS X → All
Hardware: x86 → All
Summary: Poor handling of sequence of ifs equivalent to a switch statement → Odinmonkey, IM: Poor handling of sequence of ifs equivalent to a switch statement
I suggested a while back to add a way to balance comparisons in some-kind of decision diagram, such as when we have a switch made out of string-cases, we can reduce the number of comparison to a log of it.  The optimization I was thinking of would be independent of the bytecode representation, for all sequences of condition which are side-effect-free.
(Assignee)

Updated

4 years ago
Assignee: general → nobody

Comment 3

2 months ago
Per policy at https://wiki.mozilla.org/Bug_Triage/Projects/Bug_Handling/Bug_Husbandry#Inactive_Bugs. If this bug is not an enhancement request or a bug not present in a supported release of Firefox, then it may be reopened.
Status: NEW → RESOLVED
Last Resolved: 2 months ago
Resolution: --- → INACTIVE
Status: RESOLVED → REOPENED
Resolution: INACTIVE → ---
You need to log in before you can comment on or make changes to this bug.