GithubHelp home page GithubHelp logo

luwes / js-diff-benchmark Goto Github PK

View Code? Open in Web Editor NEW
65.0 65.0 5.0 2.12 MB

Simple benchmark for testing your DOM diffing algorithm.

JavaScript 79.25% HTML 20.75%
algorithm benchmark diffing dom

js-diff-benchmark's People

Contributors

dy avatar freak613 avatar luwes avatar webreflection avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

js-diff-benchmark's Issues

won't run in Win10 :/

$ npm test

> [email protected] test D:\doc\prog\learn\js\vdom\js-diff-benchmark
> node --expose-gc src/bench.js

D:\doc\prog\learn\js\vdom\js-diff-benchmark\src\utils.js:29
    mutations.push(`remove: drop(${oldNode.textContent})`);
                                           ^

TypeError: Cannot read property 'textContent' of undefined
    at Dommy.container.removeChild (D:\doc\prog\learn\js\vdom\js-diff-benchmark\src\utils.js:29:44)
    at module.exports (D:\doc\prog\learn\js\vdom\js-diff-benchmark\libs\spect.js:20:18)       
    at create1000 (D:\doc\prog\learn\js\vdom\js-diff-benchmark\src\utils.js:82:14)
    at D:\doc\prog\learn\js\vdom\js-diff-benchmark\src\bench.js:75:20
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (D:\doc\prog\learn\js\vdom\js-diff-benchmark\src\bench.js:58:6)     
    at Module._compile (internal/modules/cjs/loader.js:1147:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
    at Module.load (internal/modules/cjs/loader.js:996:32)
    at Function.Module._load (internal/modules/cjs/loader.js:896:14)

TY :)

nextSibling issue

  let parent = new Dommy()
  const childNodes = [];
  for (let i = 0; i < 100; i++) childNodes.push(new Nody(parent, i));

  console.log(childNodes[0].nextSibling)  // here it's end node
  parent.appendChild(childNodes[1])
  console.log(childNodes[0].nextSibling) // here it's childNodes[1]

Are README numbers updated?

Results seems quite off on my laptop (Dell XPS i7) so I wonder if there's some update needed, as I can see consistently udomdiff faster than others as overall usage.

js-diff-benchmark

Is there a Replace Test?

Replace is slightly different than clear and insert as it has to first realize that it can't keep anything that's there. I thought I saw it before maybe? Was it removed?

Consistent results

At the moment results could be skewed quite a bit from run to run.

Ideally each test should run a minimum of 3 times, randomize library order at least, and take some average

Fix list-difference swap w/ minimum added bytes

Pretty impressed with how this script performs only the swapping at the moment requires way more extra operations than is needed.

Would be nice to see this fixed with minimum size added.

Screen Shot 2020-04-15 at 9 40 05 AM

snabbdom is broken on prepend/insert

  // insert
  diff(parent,[], [e1,e3,e5], null);
  diff(parent,[...parent.childNodes],[e1,e2,e3,e4,e5], null);
  parent.childNodes // e1, e2, e3, e5, e4

  // prepend
  diff(parent,[], [e4,e5], null);
  diff(parent,[e4,e5],[e1,e2,e3,e4,e5], null);
  parent.childNodes // e4, e5, e1, e2, e3

That is so regardless of the last argument.

PR to add domdiff

Hi I would like to see domdiff in here too.
Thought about creating a PR but do not want to be rude.

Give weight to DOM mutations (in addition to pure algo)

The test at the moment measures the algorithm but it doesn't correlate to real life where the number of DOM mutations can have a bigger impact than the algorithmic logic.

It would be interesting to see if giving weight (take more time) to these operations could simulate a real browser environment better.

Probably better start using playwright or puppeteer at that point
https://github.com/puppeteer/puppeteer
https://github.com/microsoft/playwright

Consider adding `random` shuffle in the mix

Another interesting test to put in the mix:

diff(
    parent,
    parent.childNodes,
    parent.childNodes.sort(() => Math.random() - Math.random()),
    get,
    parent.lastElementChild
  );

Warning

snabdom here fails 1 out of 3 times so that tests should likely be put in try/catch and warn in red the test broke/didn't work.

You can give it a try with 1000 rows already, launch it few times and see snabdom fall.

I might file an issue in there though ... or maybe they know already.

Note on Update every 10th row

I think it is good to know. And it is definitely a consideration for libraries in general. But I wanted to point out from a reactive standpoint I think this test doesn't matter for the list reconciler very much. Nested updates unless they replace the whole element avoid the list reconciler (which is why reactive is fast). From this perspective I think that makes udomdiff still the better choice for a reactive library?

EDIT: I see replace is the big one. Probably because doesn't do the shortcut there. I wonder how much code that'd take to remedy. And the scaling of append. Interesting. That deserves further investigation.

Correctness of the benchmark

As I understand, results published in README are results from running tests on node.
After running benchmark multiple times on Chrome 89 with 6x CPU throttling I barely can get 3% difference between stage0 and udomdiff reconcilers, while results in node (and README) look like there is almost x3 slowdown difference between them.
Results between 5 of 6 libraries are very minimal, with only heckel having noticeable hit.
I would recommend to use only browser results, they do not change the winner, but can ease bad representation of other libraries. Also I think results in the browser are much more stable, especially with throttling, without hunting for randomized milliseconds in node.

Screenshot 2021-04-07 at 20 58 33

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.