react-native icon indicating copy to clipboard operation
react-native copied to clipboard

[Bridge] RCTRootView and RCTBridge can only be created with URL

Open jwyld opened this issue 11 years ago • 5 comments

Going through the work of providing a URL to the source is actually slower (noticeably so) for a situation when I have the JS string already.

Speed of startup is very important for me. I have the JS code mapped from disk and in Unicode format already. If I could hand the string I have to the root view creation or to a bridge and then into a root view, this would be a huge win for me. This would bypass the NSURLSessionDataTask as well as the cost of the NSString allocation for the raw text in the JS loader. Additionally, it speeds up the cost of lex in JavaScriptCore by a fraction because the calls through NSString are faster when dealing with native Unicode.

jwyld avatar May 30 '15 17:05 jwyld

To generalize would it make sense to expose the JS loader and allow custom implementations to be injected? One thing I've wanted to do with the loader is also have a better notion of progress, so custom loaders would let me achieve that and address this issue at the same time.

ide avatar May 30 '15 21:05 ide

You can use a base64 data URL containing the entire JS file as a string. Is that a viable solution for you?

nicklockwood avatar Jun 01 '15 16:06 nicklockwood

@nicklockwood "Speed of startup is very important for me." base64 is going to add way too much overhead. In my case, I have a mapped Unicode string. By using such, I pay no cost for CFString to convert from UTF8. Since it's a "native" string, it removes much of the string overhead cost for lex as well.

jwyld avatar Jun 01 '15 17:06 jwyld

Fair enough. It should be fairly simple to add an alternative constructor to RCTBridge that accepts a script string. If you want to make a PR for it, I'm happy to review.

nicklockwood avatar Jun 01 '15 18:06 nicklockwood

The delegate should address this.

ide avatar Aug 15 '15 05:08 ide