Chevrotain / chevrotain

Parser Building Toolkit for JavaScript
https://chevrotain.io
Apache License 2.0
2.44k stars 200 forks source link

Fastest parser on Windows, but incredibly slow in both Edge and Safari on Mac/iPad/iPhone #1841

Closed pizberg closed 1 year ago

pizberg commented 1 year ago

Window Edge: image

iPhone Edge: 95159f37cbb36378e1a49d08169747e

msujew commented 1 year ago

Hey @pizberg,

as stated in the docs, Chevrotain is optimized to run very well on the V8 engine, which is used in Edge and Chromium and most notably Node.js. Since Apple does not allow other web engines on their mobile devices, both Edge and Safari use the webkit engine.

So, Chevrotain being slower on other platforms is kind of expected in that regard. Do you have special requirements that need you to run a lot of data through Chevrotain on Mac/mobile devices? I would imagine that the high performance of Chevrotain is only really useful when you start parsing lot of source code in server environments (Node.js).

pizberg commented 1 year ago

Hi, @msujew , Thanks for the explanation. I'm just confused by the test results, not for any high performance requirement with webkit engine.

bd82 commented 1 year ago

Hello.

This is not a Windows / Mac question, instead it is about the JavaScript engine used.

Chevrotain is generally optimized for V8 (Chrome / NodeJS / Edge (in newer versions)).

There are a few factors that can affect this:

  1. Chevrotain feature development performance benchmarks is normally done on Chrome (V8), but not other JS engines.
  2. Chevrotain implements some performance optimizations specifically for V8, but not for other engines.
  3. Chevrotain has no code generation phase, so it cannot produce "simple" parsing code that is easily optimized by any JS engine (or alternatively in hand-crafted parser example), so the more advanced the JS engine is the more Chevrotain can potentially benefit.

Here are my results on my M1 MacBook Pro

bd82 commented 1 year ago

Since Apple does not allow other web engines on their mobile devices, both Edge and Safari use the webkit engine.

Oh, I did not know Edge of mobile IOS does not use V8

msujew commented 1 year ago

@bd82 Apple is quite clear on that in their review guidelines. No app published on the app store is allowed to bring their own JS/Web rendering engine.

pizberg commented 1 year ago

Hi, @bd82 Thanks, this information is useful

bd82 commented 1 year ago

I'll close this for now, re-open if there are any other related questions.

mattbishop commented 1 year ago

It might be a good idea to revisit the code to see if it is still valid. I see a more recent approach here: https://github.com/sindresorhus/to-fast-properties/blob/main/index.js

bd82 commented 1 year ago

Thanks @mattbishop I actually did attempt to use this more modern version, see details here: