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

Performance improvements #11

Open
Swizz opened this issue May 12, 2017 · 18 comments
Open

Performance improvements #11

Swizz opened this issue May 12, 2017 · 18 comments

Comments

@Swizz
Copy link
Owner

Swizz commented May 12, 2017

I'm curious to know more about how to measure performance in op/sec, to have a comparison between :

  • snabbdom-pragma 2.1.0
  • snabbdom-pragma 1.10.0
  • snabbdom/h 0.6.6
@Swizz
Copy link
Owner Author

Swizz commented May 13, 2017

Bad news...

Snabbdom-pragma@1  =>  20346 op/s [avg: 0.491ms]
Snabbdom-pragma@2  =>  9622 op/s [avg: 1.039ms]
Snabbdom/h  =>  65803 op/s [avg: 0.152ms]

for

Snabbdom.createElement('div', null, 'Hello', 13)

@Swizz
Copy link
Owner Author

Swizz commented May 13, 2017

Plan to move to Ramda Lodash instead of builtin map/reduce/filter ?

@Swizz
Copy link
Owner Author

Swizz commented May 13, 2017

Partial lodash experiment :

Snabbdom-pragma@1  =>  21607 op/s [avg: 0.462ms]
Snabbdom-pragma@2  =>  27133 op/s [avg: 0.368ms] (lodash here)
Snabbdom/h  =>  67558 op/s [avg: 0.148ms]
  • take note the fact that h is literally doing nothing

@Swizz
Copy link
Owner Author

Swizz commented May 14, 2017

Which is better ? Speed or Weight ?

@Swizz
Copy link
Owner Author

Swizz commented May 14, 2017

I aimed to be dependency free. So what about using is and lodash and produce a dist file which be dependency free with tree shacking ?

@Swizz
Copy link
Owner Author

Swizz commented May 16, 2017

@jvanbruegge Are Snabbdom-pragma performances for Snabbdom and Cyclejs users a priority ?

@jvanbruegge
Copy link
Contributor

I would go for dependency free, as this is affecting the users bundle size.
I think Prepack can get rid of the snabbdom-pragma overhead.
Can you test it too?

@Swizz
Copy link
Owner Author

Swizz commented May 16, 2017

I made a brief tests, and seen a tiny difference regarding the lodash implementation ones.

The prepack stuffs need to be done after the project use of Snabbdom.createElement, at our state, this is unrelevant.

Only the dist/index.js is used in most case with the basic import ... from .... So, it could be good to import with tree shacking only the requested functionnalities from Lodash, isnt it ?

@jvanbruegge
Copy link
Contributor

what is the compiled js after prepack? Sorry, I'm on mobile

@Swizz
Copy link
Owner Author

Swizz commented May 16, 2017

On mobile too, I'll take a look after lunch.

@Swizz
Copy link
Owner Author

Swizz commented May 16, 2017

Here you are

Prepack isnt in love with exports/require, so it needed to do some hacks to work with..
Prepack didn't replace Array.prototype.map, Array.prototype.reduce, etc.., functions that are costly for us.
Prepack works fine for the finnal duty at the production bundling, not our case.
Prepack will be good after transpiling, to catch Snabbdom.createElement invariant results.

@jvanbruegge
Copy link
Contributor

I mean prepack on the file that is using JSX.
I assume that it optimizes snabbdom-pragma away and replaces it with just the correct h call

@jvanbruegge
Copy link
Contributor

How much does lodash add to the size?

@Swizz
Copy link
Owner Author

Swizz commented May 16, 2017

Following @caridy response :

It does return just an object, and yes, h() does more, it has a great deal of flexibility in the order of the arguments, and it supports compound sel value, but neither of those are things that you care about because they can't be express in JSX, so, for you it will be the same. I also recommend creating a custom h() for projects that are mores restrictive, and expect better perf by removing all that logic that we have in h().

Snabbdom@2 is not calling h() anymore


In fact, we loose in perf due to the switch from for loop to map/reduce.

Snabbdom-pragma@1 was 2.76 KB (1.67 KB compressed)
Snabbdom-pragma@2 is 4.9 KB (3.0 KB compressed)

I were happy to rewrite Snabbdom-pragma in a more FP way following the Snabbdom contributor advice, but I realise, it was a big loss in all points.

Some ES6 features I overuse result to a big transpiled code. Destructuring, rest operator, etc..


For lodash size, I'll need to try, but we can count 3 or 4 functions : flatten, map, reduce, fromPairs (?).
So we can hope no more than 1 KB.

@Swizz
Copy link
Owner Author

Swizz commented May 16, 2017

I dont know how this is calculated, but npm-cost, give me other results :
https://cost-of-modules.herokuapp.com/[email protected]
https://cost-of-modules.herokuapp.com/[email protected]

snabbdom-pragma@1 : 3.49 KB
snabbdom-pragma@2 : 3.56 KB

@Swizz Swizz changed the title Performance testing Performance improvements May 29, 2017
@Swizz Swizz added this to the future milestone May 29, 2017
@blikblum
Copy link
Collaborator

Snabbdom-pragma@1 => 20346 op/s [avg: 0.491ms]
Snabbdom-pragma@2 => 9622 op/s [avg: 1.039ms]
Snabbdom/h => 65803 op/s [avg: 0.152ms]

How do you get those numbers? I'm interested in trying to improve the performance

@Swizz
Copy link
Owner Author

Swizz commented Nov 14, 2017

I was using a custom implementation using time/timeEnd.

But we should use mafintosh/nanobench

@blikblum
Copy link
Collaborator

Do you have any script that i can get and run myself?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants