New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Polyfill around typed arrays #139
Comments
So I was thinking about this problem and because it may not be possible to have a decently performing polyfill that perfectly conforms to native typed arrays I have thought up a decent alternative as outlined below. So our biggest problem in having a polyfill that acts exactly like native typed arrays is that such as in the below example:
Having a setter(such as with So for the above code example it would become this:
I would love to hear your thoughts on this idea. |
Yeah, that makes sense, I agree. However, moving from So basically we would compile code for typed arrays, and there would be a 'wrapper' script that checks for typed arrays, then if necessary rewrites the script, then eval's it. The rewriting could be done with an AST parser like UgilifyJS, but probably this is simple enough that some regexps can handle it, I hope. |
To clarify, what makes this possible is that we know the names of our typed arrays (HEAP8, HEAP16, etc.), and nothing conflicts with them. If we didn't, this would in general be impossible. |
Yes, it would definitely be slower to have to call a function on top of array access for situations where there is native support for typed arrays and doing some sort of rewriting to work around that sounds like a great idea. I'll take more of an in-depth look into the Emscripten internals so I can better understand how this would fit into the system. I'll work on implementing this as I'm pretty excited to see this work. |
Btw, one complication I just thought of is that parsing the output in -O2 and -O3 will be much harder, since closure compiler is run on it, which renames all the variables. It's still possible, but trickier. Might make sense to ignore that case at first. |
Polyfilling this is hard, and becoming quickly less important as all browsers get typed arrays, so closing this. |
It's worth trying that shim you linked to. But I suspect it will be so much slower that it isn't worth it. Let's see numbers though. |
@kripken Thank you! |
Regarding numbers, someone with IE9 needs to get them (I don't have a windows machine myself). |
I have IE9, which exactly numbers should I get? |
I would be curious to take a benchmark, say |
This would be really nice for the Wii browser,and for similar "embedded" browsers, which cannot always be updated. That way, code which is already online, and is small/fast enough to run on these browsers (this probably would, for example), can be run out-of-the-box. |
Typed arrays are everywhere at this point, and we depend on them so heavily, I don't think we could polyfill around them in a useful way. |
https://github.com/mozilla/pdf.js/blob/master/web/compatibility.js#L7-49
is a polyfill for some of the typed arrays spec, letting older browsers use the typed arrays API (slowly).
Would be nice for emscripten to use that too, so typed array builds would work and not fail as they do now, if the environment lacks typed arrays. We do need more support than in that link, though (different size arrays, shared buffers, etc.).
The text was updated successfully, but these errors were encountered: