Closed
Bug 773859
Opened 12 years ago
Closed 12 years ago
Math.random() needs to inlined in JM
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
RESOLVED
WONTFIX
People
(Reporter: ehsan.akhgari, Unassigned)
References
(Blocks 1 open bug)
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.)
Reporter | ||
Updated•12 years ago
|
Blocks: gecko-games
Comment 1•12 years ago
|
||
In general, we've stopped adding optimizations to JM that don't also help IM. This sounds like a good IM bug, though.
Comment 2•12 years ago
|
||
Filed 774364 for tracking in Ion.
Updated•12 years ago
|
Whiteboard: [js:t] → [js:t][games:p1]
Updated•12 years ago
|
Comment 3•12 years ago
|
||
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: 12 years ago
Resolution: --- → WONTFIX
You need to log in
before you can comment on or make changes to this bug.
Description
•