Math.random() needs to inlined in JM

RESOLVED WONTFIX

Status

()

defect
RESOLVED WONTFIX
7 years ago
7 years ago

People

(Reporter: Ehsan, Unassigned)

Tracking

(Blocks 1 bug)

Trunk
x86_64
Linux
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [js:t][games:p1])

Let's say that you have a function in an emscripted program which returns a random signed int between 0 and n.  Here's how the original code looks like:

 int rand(int max) {
   return (unsigned long)(emscripten_random() * 0x8fffffff) % max;
 }

Here's how the js function with -O2 --closure 0 looks like:

 function _emscripten_random() {
   return Math.random();
 }

 function _rand($max) {
   var $1 = _emscripten_random();
   var $2 = $1 * 2415919104;
   var $3 = $2 >= 0 ? Math.floor($2) : Math.ceil($2);
   return ($3 >>> 0) % ($max >>> 0);
 }

In my profile, I see a lot of call overhead to Math.random().  Looking at the implementation, it seems like it could possibly be inlined in the jitted code, which would avoid the call overhead (which in my profile takes about 50% of the entire _rand() function.)
Blocks: gecko-games
In general, we've stopped adding optimizations to JM that don't also help IM.  This sounds like a good IM bug, though.
Filed 774364 for tracking in Ion.
Blocks: WebJSPerf
Whiteboard: [js:t]
Whiteboard: [js:t] → [js:t][games:p1]
Depends on: 587255
Blocks: 587255
No longer depends on: 587255
Should this bug be closed and/or duped to bug 774364 per comments 1 and 2?
Don't care about this in JM any more; the IM bug is in 774364.
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.