GithubHelp home page GithubHelp logo

Comments (4)

tmikov avatar tmikov commented on April 30, 2024 2

We are currently working on a native implementation of TextEncoder. So that will be much faster soon.

from hermes.

tmikov avatar tmikov commented on April 30, 2024 1

Hermes is an interpreter optimized for very fast startup and small binary size. You are comparing it against JSC, which is a type specializing JIT. At a steady state, given enough time to warm up, a JIT will always have a perf advantage. So, this is expected.

I extracted the benchmark from your code:

function testConvert1() {
  const startTime = Date.now();
  const byteArray = new Uint8Array(10000000);
  for (let n = 0; n < byteArray.length; n++) {
  }
  print("ExecutionTime = ", Date.now() - startTime);
}

This code, a tight array loop that does nothing, is particularly advantageous for a JIT. A JIT could legitimately optimize out the entire loop, bringing the time down to 0. By comparison, the JIT will have much harder time optimizing multiple small routines with allocations, etc.

If we modify the code to actually do something, and keep the typed array length in a variable to avoid fetching it all the time, we get this:

function testConvert2() {
  const startTime = Date.now();
  const byteArray = new Uint8Array(10000000);
  let sum = 0;
  for (let n = 0, len = byteArray.length; n < len; n++) {
    sum += byteArray[n];
  }
  print(sum, "ExecutionTime = ", Date.now() - startTime);
}

I ran this code with Hermes, v8 and JSC, with their JITs on and off:

- hermes          104 ms
- v8 --jitless    179 ms
- jsc --useJIT=0  116 ms
- v8               10 ms
- jsc              10 ms

As an interpreter, Hermes is currently on par in performance and often has an advantage.

With all that said, we realize that there are situations where more performance is needed, and Hermes is unable to serve them well. That's why we are working on Static Hermes, which will be much faster.

Running the same benchmark with Static Hermes currently takes 14ms, so we are very close and keep improving.

from hermes.

maksimlya avatar maksimlya commented on April 30, 2024

Ok, understood, thx for answer. There's also some other performance differences I've noticed, I posted it in react-native project but they said I should look into library's authors, altho I think issue is with some of the low-level api's.

I was looking at TextEncoder(from 'text-encoding' lib) and cheerio(jQuery) performace, and saw they perform much worse on React Native compared to webview/NodeJS and about as twice worse on Hermes compared to JSC.

TextEncoder in my example(on 100kb input) takes ~170 ms, while webview takes 1-2 ms (both Android and iPhone) and NodeJS takes 14 ms (I suppose it has to do something with WebAPI optimizations).

Another case, cheerio(JQuery) performance -when I try to perform some HTML manipulation via cheerio, I also saw big hit if compared to other platforms:

RN With Hermes(Redmi note 9): 3500 ms
RN JSC(Redmi note 9): 1700 ms
Android Webview(Redmi note 9): 150-200 ms
iOS Webview(iphone XR): 90 ms
NodeJS(Mac mini 2018): 150 ms

from hermes.

maksimlya avatar maksimlya commented on April 30, 2024

I am now trying to workaround the TextEncoder via JSI/Golang and if it goes well then might attempt to do same with cheerio, altho that one might be bulky.

from hermes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.