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

Does hermes make some specific optimized for React.js or related js framework? #55

Closed
wanhongbo opened this issue Jul 19, 2019 · 2 comments

Comments

@wanhongbo
Copy link

wanhongbo commented Jul 19, 2019

Hi,
I am trying to test the hermes to my android application but do not use RN.I added the related hermes
librarys and head files to my project and then after compiling and linking.It works in my application.
Previously I use the JavascriptCode as my js engine in my project and I make my test code like this:

            //const char *source = GetJSCode("/sdcard/vue.min.js", "");
            //const char *source = GetJSCode("/sdcard/react-dom.production.min.js", "");
            const char *source = GetJSCode("/sdcard/react.min.js", "");
            //const char *source = GetJSCode("/sdcard/af-appx.worker.min.js", "");
            {
                    //test js use Hermes
                    LOGD("Hermes Test case 2! source=%s",source);
                    std::string hermesJs(source);
                    auto jsiBuffer = std::make_shared<facebook::jsi::StringBuffer>(hermesJs);
                    auto runtime = facebook::hermes::makeHermesRuntime();
                    double start1 = now();
                    auto bytecode = runtime->prepareJavaScript(jsiBuffer, "whb test");
                    LOGD("Hermes  ByteCode Gen cost=%f!",now()-start1);
                    double start2 = now();
                    runtime->evaluatePreparedJavaScript(bytecode);
                    LOGD("Hermes evaluate bytecode cost=%f",now()-start2);
            }
            //test js use JSC
            {
                  std::string js(source);
                  std::string exeption;
                  ...
                  double start3= now();
                  context->ExecuteJavaScript(js, &exeption);
                  LOGD("JSC evaluate script cost=%f",now()-start3);
            }   

First,I try to use the react.min.js to feed the hermes and JSC,the data is below and looks good:

c++: Hermes  ByteCode Gen cost=12.038574!
c++: Hermes evaluate bytecode cost=0.323975
c++: JSC evaluate script cost=3.677734

then,I try to use the vue.js to feed the hermes and jsc,the data is below:

c++: Hermes  ByteCode Gen cost=6.109131!
c++: Hermes evaluate bytecode cost=40.747314
c++: JSC evaluate script cost=18.967041

The JSC is fast a lot than the hermes even JSC use the pure javascript string and hermes use the bytecode .

So,I wanna to know,does the hermes make some specific optimize for react related javascript?and worried about whether other javascript can benfit form hermes.

@mhorowitz
Copy link
Contributor

Hermes optimizes for its primary metrics of startup time, size, and memory utilization. These aren't specific to React Native, but they were informed by it.

Hermes makes different trade-offs than other VMs in order to optimize for its core metrics. In particular, Hermes has no JIT (just in timer compiler), because JITs are mainly useful for improving the performance of longer running, CPU intensive programs. A JIT also consumes more memory than an interpreter. I expect that JS which is not React Native can benefit from Hermes, but not that Hermes will be an improvement for all possible JS programs.

Given the very long evaluation time of vue.js on both VMs which you have measured, I suspect that the JIT is kicking in and JSC execution benefits from this.

@mhorowitz
Copy link
Contributor

Another observation (thanks to @jbower-fb) is that if you use prepareJavaScript() on device, you are not getting the most optimized possible code. This is a tradeoff to reduce on-device compilation time and is intended for simple code or testing on slow devices. For production use, the engine design expects that the JS source is compiled offline. You should use the command line hermes compiler, with the -O flag to generate bytecode with full optimizations.

Another optimization which RN uses which you can use, too, is to mmap the bytecode instead of eagerly loading it. https://github.com/facebook/hermes/blob/master/API/jsi/jsi/jsilib.h#L14 is some library code which will do this for you.

facebook-github-bot pushed a commit that referenced this issue Mar 24, 2021
Summary:
dogscience

I'm just throwing code against the (gradle) wall and see what sticks.
The problem with the previous setup was that it created two
publications. While the outcome looked fine in general, it created
two POM files which overwrote each other and the latter one created
would not have all the meta data, causing Maven Central validation
to fail.

With this we're modifying the existing one(s) to add the headers JAR
instead.

Pull Request resolved: facebookincubator/fbjni#55

Test Plan:
./gradlew installArchives

Checked my ~/.m2/ and now there's only one distribution, i.e. not
multiple installations and, importantly, only one POM file.

Reviewed By: IvanKobzarev

Differential Revision: D27290376

Pulled By: passy

fbshipit-source-id: d3e0a713ccec381f518867594607554d35f0b88e
mganandraj pushed a commit to mganandraj/hermes that referenced this issue Nov 29, 2021
Add win32 exports for creating a runtime with a default CrashManager implementation that forwards calls into Windows Error Reporting (Watson) and a crashHandler that can output details (such as callstack) to a file handle.
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

2 participants