Skip to content
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

WebAssembly support? #113

Open
stephenemslie opened this issue Jun 20, 2019 · 14 comments
Open

WebAssembly support? #113

stephenemslie opened this issue Jun 20, 2019 · 14 comments

Comments

@stephenemslie
Copy link

Will jsc-android include WebAssembly support?

From what I can see, WebAssembly seems to be explicitly disabled in jsc-android, but appears to be supported by the current JavascriptCore. Is there any intention to remove the --no-webassembly flag from jsc-android?

My own motivation is to run emscripten-compiled modules in react-native. Unfortunately they aren't performing well under emscripten's fallback to asm.js.

@Ivshti
Copy link

Ivshti commented Jun 20, 2019

I'm looking for the same thing.

We're developing an app that shares a module that compiles to WASM with a web app, and we're avoiding native module cause of the inability to upgrade via CodePush.

Can you share some insights on what the performance hit is with asm.js?

@stephenemslie
Copy link
Author

@Ivshti With expo 33 releasing the new expo-random api, I've been experimenting with running libsodium.js under managed expo. Everything runs smoothy on the emulator, but on my device the app crashes without explanation as soon as require('libsodium-wrappers') is called.

Running logcat during the crash spits out a lot of noise, but turned this up:

06-24 11:40:02.339   685   685 E lowmemorykiller: Error writing /proc/18483/oom_score_adj; errno=22

From what I can see, the emscripten-compiled libsodium library is attempting to detect the WebAssembly global, falling back to asm.js when that fails, and then consuming a lot of memory and getting killed by the OS. It's unclear to me whether the application is actually running out of memory or just dying while adjusting it's oom score (not sure why it's failing to write to oom_score_adj), but either way it seems to be consuming a significant chunk of memory and dying.

I'd be curious to compare the wasm and asm.js memory usage on a browser to see if there's a big difference.

@Kudo
Copy link
Member

Kudo commented Jun 26, 2019

JSC's WebAssembly support relies on FTL JIT which we disabled for memory usage and binary size.
Did you ever try WebAssembly on RN iOS?
AFAIK, WebAssembly is not supported on JSC iOS.

@9468305
Copy link

9468305 commented Oct 11, 2019

My latest investigation is WebAssembly is supported on JSC iOS Device, but not on JSC iOS Emulator.

@jzxchiang1
Copy link

WebAssembly works on both JSC iOS Device and JSC iOS Emulator (for iOS 14).

It doesn't work on JSC Android at all.

@aguycalled
Copy link

ios 15.2 simulator works with webassembly but real device with the same version fails with “Can’t find variable: WebAssembly” any clue how to solve it?

@jzxchiang1
Copy link

That's so strange. AFAIK WebKit never removed support for WebAssembly. Why would it not be able to find WebAssembly...?

@aguycalled
Copy link

Isn’t JSC used by default? Is there any reason why Simulator and Real device would use something different?

I’ve seen a similar issue being commented here: https://forum.dfinity.org/t/making-http-calls-from-mobile-apps/5192/33

@jzxchiang1
Copy link

Yeah, JSC is used by default. I have no idea why they'd be different. Is your simulator also using iOS 15.2, or is it 15.3 or something else?

WebAssembly is definitely supported by Safari 15.2, which is the version of Safari that's bundled by default with iOS 15.2 https://webkit.org/blog/12140/new-webkit-features-in-safari-15-2/

I can't imagine they removed WebAssembly from the JS globals either. In fact, on stackoverflow, I can see other developers are indeed running wasm apps on iOS 15. Have you tried on a different iOS device by any chance? (I will try with one as well once I get a chance.)

@aguycalled
Copy link

aguycalled commented Jan 21, 2022 via email

@aguycalled
Copy link

I could not get my hands on another device yet, but I filed a report with Apple and this is their answer:

React-Native is using JavaScriptCore.framework, and it does not have JIT.
WebAssembly implementation requires JIT, so, if we would like to use it, please use WKWebView.

@jzxchiang1
Copy link

I could not get my hands on another device yet, but I filed a report with Apple and this is their answer:

React-Native is using JavaScriptCore.framework, and it does not have JIT. WebAssembly implementation requires JIT, so, if we would like to use it, please use WKWebView.

Wow, can you ask them why it works on iOS 14 but not 15? And why it works on iOS Simulator but not an iPhone device?

I'd be very curious to see a link to the report, if it's public. Thanks.

@Kudo
Copy link
Member

Kudo commented Jan 22, 2022

React-Native is using JavaScriptCore.framework, and it does not have JIT. WebAssembly implementation requires JIT, so, if we would like to use it, please use WKWebView.

this aligns to my understandings. for security reason, ios has W^X protection for apps, so JIT and WebAssembly are not feasible (Safari or WKWebView are exception).
other reference: NativeScript/ios#89

@jzxchiang1
Copy link

jzxchiang1 commented Jan 22, 2022

That's strange. I've called WebAssembly from within RN JS on my iPhone SE (iOS 14.6) device in both debug and release mode, and it's worked.

I wonder if they added JIT support in iOS 14.2 and then removed it again in iOS 15?

EDIT: From reading that thread you linked, I think it might also be because my app was built using XCode for local development. Apparently once you send the final app to the App Store, then JIT permissions are removed...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants