Skip to content

Commit 14dc219

Browse files
Ashok Menonfacebook-github-bot
authored andcommitted
Deleting Optimized Bundle!
Reviewed By: javache Differential Revision: D4566164 fbshipit-source-id: 1fbd3dd04f24399e93e3c6ec58956e6e18f1683f
1 parent 7c97008 commit 14dc219

File tree

13 files changed

+27
-271
lines changed

13 files changed

+27
-271
lines changed

ReactAndroid/src/main/java/com/facebook/react/cxxbridge/CatalystInstanceImpl.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,9 @@ private native void initializeBridge(ReactCallback callback,
208208
jniLoadScriptFromFile(fileName, sourceURL);
209209
}
210210

211-
/* package */ void loadScriptFromOptimizedBundle(String path, String sourceURL, int flags) {
212-
mSourceURL = sourceURL;
213-
jniLoadScriptFromOptimizedBundle(path, sourceURL, flags);
214-
}
215-
216211
private native void jniSetSourceURL(String sourceURL);
217212
private native void jniLoadScriptFromAssets(AssetManager assetManager, String assetURL);
218213
private native void jniLoadScriptFromFile(String fileName, String sourceURL);
219-
private native void jniLoadScriptFromOptimizedBundle(String path, String sourceURL, int flags);
220214

221215
@Override
222216
public void runJSBundle() {

ReactAndroid/src/main/jni/xreact/jni/CatalystInstanceImpl.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ void CatalystInstanceImpl::registerNatives() {
105105
makeNativeMethod("jniSetSourceURL", CatalystInstanceImpl::jniSetSourceURL),
106106
makeNativeMethod("jniLoadScriptFromAssets", CatalystInstanceImpl::jniLoadScriptFromAssets),
107107
makeNativeMethod("jniLoadScriptFromFile", CatalystInstanceImpl::jniLoadScriptFromFile),
108-
makeNativeMethod("jniLoadScriptFromOptimizedBundle",
109-
CatalystInstanceImpl::jniLoadScriptFromOptimizedBundle),
110108
makeNativeMethod("jniCallJSFunction", CatalystInstanceImpl::jniCallJSFunction),
111109
makeNativeMethod("jniCallJSCallback", CatalystInstanceImpl::jniCallJSCallback),
112110
makeNativeMethod("getMainExecutorToken", CatalystInstanceImpl::getMainExecutorToken),
@@ -217,14 +215,6 @@ void CatalystInstanceImpl::jniLoadScriptFromFile(const std::string& fileName,
217215
}
218216
}
219217

220-
void CatalystInstanceImpl::jniLoadScriptFromOptimizedBundle(const std::string& bundlePath,
221-
const std::string& sourceURL,
222-
jint flags) {
223-
return instance_->loadScriptFromOptimizedBundle(std::move(bundlePath),
224-
std::move(sourceURL),
225-
flags);
226-
}
227-
228218
void CatalystInstanceImpl::jniCallJSFunction(
229219
JExecutorToken* token, std::string module, std::string method, NativeArray* arguments) {
230220
// We want to share the C++ code, and on iOS, modules pass module/method

ReactAndroid/src/main/jni/xreact/jni/CatalystInstanceImpl.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ class CatalystInstanceImpl : public jni::HybridClass<CatalystInstanceImpl> {
5757

5858
void jniLoadScriptFromAssets(jni::alias_ref<JAssetManager::javaobject> assetManager, const std::string& assetURL);
5959
void jniLoadScriptFromFile(const std::string& fileName, const std::string& sourceURL);
60-
void jniLoadScriptFromOptimizedBundle(const std::string& bundlePath, const std::string& sourceURL, jint flags);
6160
void jniCallJSFunction(JExecutorToken* token, std::string module, std::string method, NativeArray* arguments);
6261
void jniCallJSCallback(JExecutorToken* token, jint callbackId, NativeArray* arguments);
6362
local_ref<JExecutorToken::JavaPart> getMainExecutorToken();

ReactCommon/cxxreact/Executor.cpp

Lines changed: 0 additions & 85 deletions
This file was deleted.

ReactCommon/cxxreact/Executor.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ class JSExecutor {
6666
virtual void loadApplicationScript(std::unique_ptr<const JSBigString> script,
6767
std::string sourceURL) = 0;
6868

69-
/**
70-
* Execute an application script optimized bundle in the JS context.
71-
*/
72-
virtual void loadApplicationScript(std::string bundlePath, std::string source, int flags);
73-
7469
/**
7570
* Add an application "unbundle" file
7671
*/

ReactCommon/cxxreact/Instance.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,6 @@ void Instance::loadScriptFromFile(const std::string& filename,
9090
nativeToJsBridge_->loadApplication(nullptr, std::move(script), sourceURL);
9191
}
9292

93-
void Instance::loadScriptFromOptimizedBundle(std::string bundlePath,
94-
std::string sourceURL,
95-
int flags) {
96-
SystraceSection s("reactbridge_xplat_loadScriptFromOptimizedBundle",
97-
"bundlePath", bundlePath);
98-
nativeToJsBridge_->loadOptimizedApplicationScript(std::move(bundlePath),
99-
std::move(sourceURL),
100-
flags);
101-
}
102-
10393
void Instance::loadUnbundle(std::unique_ptr<JSModulesUnbundle> unbundle,
10494
std::unique_ptr<const JSBigString> startupScript,
10595
std::string startupScriptSourceURL) {

ReactCommon/cxxreact/Instance.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class Instance {
3939
void loadScriptFromString(std::unique_ptr<const JSBigString> string, std::string sourceURL);
4040
void loadScriptFromStringSync(std::unique_ptr<const JSBigString> string, std::string sourceURL);
4141
void loadScriptFromFile(const std::string& filename, const std::string& sourceURL);
42-
void loadScriptFromOptimizedBundle(std::string bundlePath, std::string sourceURL, int flags);
4342
void loadUnbundle(
4443
std::unique_ptr<JSModulesUnbundle> unbundle,
4544
std::unique_ptr<const JSBigString> startupScript,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2004-present Facebook. All Rights Reserved.
2+
3+
#include "JSBigString.h"
4+
5+
#include <fcntl.h>
6+
#include <stdio.h>
7+
#include <sys/stat.h>
8+
9+
#include <folly/Memory.h>
10+
#include <folly/ScopeGuard.h>
11+
12+
namespace facebook {
13+
namespace react {
14+
15+
std::unique_ptr<const JSBigFileString> JSBigFileString::fromPath(const std::string& sourceURL) {
16+
int fd = ::open(sourceURL.c_str(), O_RDONLY);
17+
folly::checkUnixError(fd, "Could not open file", sourceURL);
18+
SCOPE_EXIT { CHECK(::close(fd) == 0); };
19+
20+
struct stat fileInfo;
21+
folly::checkUnixError(::fstat(fd, &fileInfo), "fstat on bundle failed.");
22+
23+
return folly::make_unique<const JSBigFileString>(fd, fileInfo.st_size);
24+
}
25+
26+
} // namespace react
27+
} // namespace facebook

ReactCommon/cxxreact/JSBigString.h

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -165,71 +165,4 @@ class RN_EXPORT JSBigFileString : public JSBigString {
165165
mutable const char *m_data; // Pointer to the mmaped region.
166166
};
167167

168-
class JSBigOptimizedBundleString : public JSBigString {
169-
public:
170-
enum class Encoding {
171-
Unknown,
172-
Ascii,
173-
Utf8,
174-
Utf16,
175-
};
176-
177-
JSBigOptimizedBundleString(int fd, size_t size, const uint8_t sha1[20], Encoding encoding) :
178-
m_fd(-1),
179-
m_size(size),
180-
m_encoding(encoding),
181-
m_str(nullptr)
182-
{
183-
folly::checkUnixError(
184-
m_fd = dup(fd),
185-
"Could not duplicate file descriptor");
186-
187-
memcpy(m_hash, sha1, 20);
188-
}
189-
190-
~JSBigOptimizedBundleString() {
191-
if (m_str) {
192-
CHECK(munmap((void *)m_str, m_size) != -1);
193-
}
194-
close(m_fd);
195-
}
196-
197-
bool isAscii() const override {
198-
return m_encoding == Encoding::Ascii;
199-
}
200-
201-
const char* c_str() const override {
202-
if (!m_str) {
203-
m_str = (const char *)mmap(0, m_size, PROT_READ, MAP_SHARED, m_fd, 0);
204-
CHECK(m_str != MAP_FAILED);
205-
}
206-
return m_str;
207-
}
208-
209-
size_t size() const override {
210-
return m_size;
211-
}
212-
213-
int fd() const {
214-
return m_fd;
215-
}
216-
217-
const uint8_t* hash() const {
218-
return m_hash;
219-
}
220-
221-
Encoding encoding() const {
222-
return m_encoding;
223-
}
224-
225-
static std::unique_ptr<const JSBigOptimizedBundleString> fromOptimizedBundle(const std::string& bundlePath);
226-
227-
private:
228-
int m_fd;
229-
size_t m_size;
230-
uint8_t m_hash[20];
231-
Encoding m_encoding;
232-
mutable const char *m_str;
233-
};
234-
235168
} }

ReactCommon/cxxreact/JSCExecutor.cpp

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -343,65 +343,6 @@ static const char* explainLoadSourceStatus(JSLoadSourceStatus status) {
343343
}
344344
#endif
345345

346-
#ifdef WITH_FBJSCEXTENSIONS
347-
void JSCExecutor::loadApplicationScript(
348-
std::string bundlePath,
349-
std::string sourceURL,
350-
int flags) {
351-
SystraceSection s("JSCExecutor::loadApplicationScript",
352-
"sourceURL", sourceURL);
353-
354-
if (!(flags & (UNPACKED_JS_SOURCE | UNPACKED_BYTECODE))) {
355-
throw RecoverableError("Optimized bundle with no unpacked source or bytecode");
356-
}
357-
358-
String jsSourceURL(m_context, sourceURL.c_str());
359-
JSSourceCodeRef sourceCode = nullptr;
360-
SCOPE_EXIT {
361-
if (sourceCode) {
362-
JSReleaseSourceCode(sourceCode);
363-
}
364-
};
365-
366-
if (flags & UNPACKED_BYTECODE) {
367-
int fd = open((bundlePath + UNPACKED_BYTECODE_SUFFIX).c_str(), O_RDONLY);
368-
RecoverableError::runRethrowingAsRecoverable<std::system_error>([fd]() {
369-
folly::checkUnixError(fd, "Couldn't open compiled bundle");
370-
});
371-
SCOPE_EXIT { close(fd); };
372-
373-
JSLoadSourceStatus jsStatus;
374-
sourceCode = JSCreateCompiledSourceCode(fd, jsSourceURL, &jsStatus);
375-
376-
if (!sourceCode) {
377-
throw RecoverableError(explainLoadSourceStatus(jsStatus));
378-
}
379-
} else {
380-
auto jsScriptBigString = JSBigOptimizedBundleString::fromOptimizedBundle(bundlePath);
381-
if (!jsScriptBigString->isAscii()) {
382-
LOG(WARNING) << "Bundle is not ASCII encoded - falling back to the slow path";
383-
return loadApplicationScript(std::move(jsScriptBigString), sourceURL);
384-
}
385-
386-
sourceCode = JSCreateSourceCode(
387-
jsScriptBigString->fd(),
388-
jsSourceURL,
389-
jsScriptBigString->hash(),
390-
true);
391-
}
392-
393-
ReactMarker::logMarker("RUN_JS_BUNDLE_START");
394-
395-
evaluateSourceCode(m_context, sourceCode, jsSourceURL);
396-
397-
bindBridge();
398-
399-
flush();
400-
ReactMarker::logMarker("CREATE_REACT_CONTEXT_END");
401-
ReactMarker::logMarker("RUN_JS_BUNDLE_END");
402-
}
403-
#endif
404-
405346
void JSCExecutor::loadApplicationScript(std::unique_ptr<const JSBigString> script, std::string sourceURL) {
406347
SystraceSection s("JSCExecutor::loadApplicationScript",
407348
"sourceURL", sourceURL);

0 commit comments

Comments
 (0)