classnames icon indicating copy to clipboard operation
classnames copied to clipboard

Vast performance improvements;

Open xobotyi opened this issue 6 years ago • 13 comments

Reworked all implementations (regular, dedupe, bind). No breaking changes.

Benchmarks:

> node ./benchmarks/run

* local#strings x 15,466,941 ops/sec ±0.36% (92 runs sampled)
*   npm#strings x 3,646,035 ops/sec ±1.69% (88 runs sampled)
* local/dedupe#strings x 2,648,941 ops/sec ±0.19% (93 runs sampled)
*   npm/dedupe#strings x 1,470,214 ops/sec ±1.71% (94 runs sampled)

> Fastest is local#strings

* local#object x 17,545,632 ops/sec ±0.42% (93 runs sampled)
*   npm#object x 3,899,880 ops/sec ±1.32% (93 runs sampled)
* local/dedupe#object x 7,118,462 ops/sec ±0.26% (91 runs sampled)
*   npm/dedupe#object x 2,632,530 ops/sec ±0.16% (94 runs sampled)

> Fastest is local#object

* local#strings, object x 11,379,569 ops/sec ±0.44% (95 runs sampled)
*   npm#strings, object x 3,259,972 ops/sec ±0.40% (94 runs sampled)
* local/dedupe#strings, object x 2,525,953 ops/sec ±1.49% (93 runs sampled)
*   npm/dedupe#strings, object x 1,548,802 ops/sec ±0.14% (92 runs sampled)

> Fastest is local#strings, object

* local#mix x 7,226,283 ops/sec ±0.20% (95 runs sampled)
*   npm#mix x 2,521,931 ops/sec ±1.39% (93 runs sampled)
* local/dedupe#mix x 907,851 ops/sec ±0.39% (93 runs sampled)
*   npm/dedupe#mix x 667,852 ops/sec ±0.84% (95 runs sampled)

> Fastest is local#mix

* local#arrays x 3,571,391 ops/sec ±0.17% (94 runs sampled)
*   npm#arrays x 919,980 ops/sec ±0.22% (91 runs sampled)
* local/dedupe#arrays x 1,028,421 ops/sec ±1.41% (95 runs sampled)
*   npm/dedupe#arrays x 743,585 ops/sec ±0.17% (94 runs sampled)

> Fastest is local#arrays

xobotyi avatar Jul 02 '19 22:07 xobotyi

Those are some big improvements to the benchmarks @xobotyi, awesome!

I'm reviewing this now and can't see any issues with merging your changes.

Out of curiosity, would you mind annotating the PR (adding your own review is a good way to do this) with some explanations of why the changes you made improved the performance?

Thanks!

JedWatson avatar Jul 05 '19 00:07 JedWatson

Done! Glad i did help😇 (actually first time contributing to such a big, in terms of users, package🤪)

xobotyi avatar Jul 05 '19 00:07 xobotyi

The original implementation did something similar. This PR changed it to the current implementation with arrays. It seemed like readability was the main reason of switching over.

newyork-anthonyng avatar Jul 05 '19 21:07 newyork-anthonyng

@newyork-anthonyng looks kinda weird to me, to speculate readability of code you'll never read with obvious performance tradeoff in main lib usecase👺

Just saying🙊

xobotyi avatar Jul 06 '19 02:07 xobotyi

Will inspect this soon :+1:

dcousens avatar Jul 23 '19 06:07 dcousens

It very likely won't make a measurable difference, but I'm curious if string constants would be an improvement.

var EMPTY = ''
var SPACE = ' ' // (except regex already called this)
var OBJECT = 'object'
var FUNCTION = 'function'
// ...etc

It might well be that variables perform worse than literals (when not using const) since they are mutable and literals aren't.

krawaller avatar Aug 27 '19 06:08 krawaller

@krawaller there are no perf improvements if to store them in variables, even more - it can slow down due to disabling the typecheck engine optimisation on rare browsers, for them

typeof a === 'string'

will be faster than

var STR = 'string';
typeof a === STR;

or even

var type = typeof a;
type === 'string'

xobotyi avatar Aug 27 '19 09:08 xobotyi

Ah, roger that, @xobotyi!

krawaller avatar Aug 27 '19 09:08 krawaller

Are there any plans to merge this?

robertmaier avatar Dec 11 '19 11:12 robertmaier

@JedWatson , ping again. Pls help to review and merge. Thank.

ref: https://github.com/ant-design/ant-design/pull/21440

zombieJ avatar Feb 18 '20 14:02 zombieJ

cc: @JedWatson any updates on this, please?

resynth1943 avatar Jan 10 '21 20:01 resynth1943

Any updates? Is there anything blocking the perf improvement?

BleedingDev avatar Mar 30 '22 09:03 BleedingDev

@pegak nothing, imo. I can offer you a drop-in replacement https://github.com/xobotyi/cnbuilder

xobotyi avatar Mar 30 '22 10:03 xobotyi