jsep icon indicating copy to clipboard operation
jsep copied to clipboard

Unpacked size is greater than esprima & espree. Speed is similar

Open 80avin opened this issue 3 years ago • 1 comments

I was comparing it with other alternatives like esprima and espree. From what I found, esprima & espree have lot of features but have smaller Unpacked size as reported by npm.

It is relatively faster, but considering the small scope of it's features, I don't think that performance gain is beneficial. (Like if we have to run small expressions, then every library does it within 20ms and 10-20ms is not big gain).

For reference,

criteria jsep esprima espree
Unpacked size 388kB 314kB 76.4kB
Features minimal complete JS complete JS
benchmark time 274 491 417

benchmark code

import jsep from 'jsep';
import * as espree from 'espree';
import * as esprima from 'esprima';
import {Bench} from 'tinybench';

const script = '2+'.repeat(1000) + '1';

const bench = new Bench({time: 100});
bench
  .add('jsep', () => {jsep(script)})
  .add('esprima', () => {esprima.parseScript(script)})
  .add('espree', () => {espree.parse(script)})
    ;

bench.run().then(t => console.table(t.map(tt => ({name: tt.name, avg: tt.result.mean*1000, var: tt.result.variance*1000})))).catch(e => console.error(e))
/* Console
┌─────────┬───────────┬────────────────────┬────────────────────┐
│ (index) │   name    │        avg         │        var         │
├─────────┼───────────┼────────────────────┼────────────────────┤
│    0    │  'jsep'   │ 274.0221922120003  │  49.0996204188163  │
│    1    │ 'esprima' │ 491.28853894916233 │ 286.50706192948815 │
│    2    │ 'espree'  │ 417.70407563696307 │ 304.5463155112307  │
└─────────┴───────────┴────────────────────┴────────────────────┘
*/

After this, I became curious to know what is the selling point of jsep and why/when should one prefer it over others ?

80avin avatar Dec 26 '22 21:12 80avin

I think that npm reports unpacked size of all files in package (not only executable code). jsep ships with 3 different bundles (commonjs, iife, module) and sourcemaps for this

Strate avatar Dec 27 '22 07:12 Strate