How to manually optmize math.fround calls

Hi guys,
Currently I have a WebGL project that aims to run mainly on Internet Explorer 11 (i know, no official support from Unity, bad perfomance, all that. ).
The in-game performance right now is kinda ok, but during the load the browser hangs for a while doing the “optimizing out Math.fround calls”. Reading somewhere else now I know that under the hood Unity finds and replace all math.fround calls with something else. But this operation take a while in IE.
So: Anyone knows what exactly Unity replaces with what, and how can i do that before the runtime. Maybe opening each generated file manually and doing some “find/replace” or maybe doing some post-process script to do that.

Obs: I have no problem needing to send uncompressed builds if this is necessary, or doing a manual gzip compression after the edit.
Also, I`m running Unity 5.6.3

Thanks

Did you solve this? I have the same problem.

Not yet, there is only some vague information told by some unity devs in other posts, but nothing too specific to someone without more knowledge about emscripten to do this operation.

Hey @jterry ,
I may have found some solution, everything seems fine but I didnt test too much Anyway, if you can benchmark this and share the results I would be thankful as i cant do this right now.
1:
After compiling open the UnityLoader.js file
2: Find this:

loadCode(Math.fround?r:UnityLoader.Utils.optimizeMathFround(r)

and replace with this:

loadCode(r

Then you will need to edit the compiled asm code to remove the calls to the math.fround calls. In Unity 5.6.4 this reference is defined as var W=global.math.fround;
To remove all the references to it, i wrote a simple script to run in unity.
1 - Compile the webGL project as uncompressed (or if you want, you can compile as gzip and manually extract the code from the gzip file)
2 - Find the _code.unityweb file, open in an text editor, search for “math.fround” just to check if the definition is var W in your version too.
3 - Open any Unity Project. Create this script and attach to anything in the scene:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RemoveFround : MonoBehaviour
{
    public TextAsset codeFile;
    public string filename = "code.unityweb";

    private void Start()
    {
        System.Text.StringBuilder strBuilder = new System.Text.StringBuilder(codeFile.text);

        for (int x = 1; x < strBuilder.Length - 1; x++)
        {
            if (strBuilder[x] == 'W')
            {
                if ((strBuilder[x - 1] == '?' || strBuilder[x - 1] == ':' || strBuilder[x - 1] == '~' || strBuilder[x - 1] == '=' || strBuilder[x - 1] == '-' || strBuilder[x - 1] == '+' || strBuilder[x - 1] == '*' || strBuilder[x - 1] == '/' || strBuilder[x - 1] == '&' || strBuilder[x - 1] == '|' || strBuilder[x - 1] == '<' || strBuilder[x - 1] == '>' || strBuilder[x - 1] == ')' || strBuilder[x - 1] == '(' || strBuilder[x - 1] == ';' || strBuilder[x - 1] == ',' || strBuilder[x - 1] == ' ') && strBuilder[x + 1] == '(')
                {
                    strBuilder[x] = ' ';
                }
            }
        }

        string str = strBuilder.ToString();
        System.IO.File.WriteAllText(Application.dataPath + "/" + filename, str);
    }
}

Rename your code.unityweb file to code.txt, and import this file to the opened Unity Project.
Drag and drop the code.txt (an TextAsset) from project to the “codeFile” field in the inspector.
Set the filename that will be saved accordingly. Also note, that if in the definition for the Math.fround calls wasn`t W, you will need to edit this line:

if (strBuilder[x] == 'W')

After pressing play there will be a file in the path relative do dataPath with the given filename. This is the unity compiled code stripped from the Math.fround calls.
You can upload it uncompressed to your server, or manually gzip it. Just remember to use the correct filename in the unity Build .Json file

I tested this process in IE and everything ran fine, without extra lag as other solutions and without doing the “Optmizing” step

Also note that this process is sucetible to crashes, as the original definition var W=global.math.fround is still there, and if thera was an case that the replace code didn`t change IE will fail.
This can be changed changing the

var W=global.math.fround;

to

var W=function(a){return a;};

There will be no crashes if something failed, but there will be a overhead hard to find.