Skip to content

Commit 5fa4aa8

Browse files
committed
Merge branch 'master' of https://github.com/dsvorc41/js-framework-benchmark into dsvorc41-master
2 parents 3470c4c + f2b57f3 commit 5fa4aa8

File tree

15 files changed

+2560
-20
lines changed

15 files changed

+2560
-20
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ jspm_packages
2929
bower_components
3030
dist
3131

32+
# pre-built binaries for faster startup (downloaded and unzipped)
33+
pre-built-binaries
34+
35+
# test results - no need to include them in our commits
36+
webdriver-ts-results
37+
3238
.idea
3339
.vscode
3440
.DS_Store

README.md

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ The current snapshot that may not have the same quality (i.e.
4444
results might be for mixed browser versions, number of runs per benchmark may vary) can be seen [here](https://krausest.github.io/js-framework-benchmark/current.html)
4545
[![Results](images/results.png?raw=true "Results")](https://krausest.github.io/js-framework-benchmark/current.html)
4646

47+
## Keyed vs non-keyed frameworks
48+
49+
Some frameworks like react, vue.js or angular allow to create a 1:1-relationship between a data item and a DOM node by assigning a “key” attribute (or for angular specifying “trackBy” in *ngFor). If you use some identifier of the data as the key you get the “keyed” mode. Any update to the data will update the associated DOM node. If you reorder the list, the DOM nodes will be reordered accordingly.
50+
51+
The other mode is “non-keyed” and this is what e.g. vue.js uses by default for lists. In this mode a change to the data items can modify DOM nodes that were associated with other data before. This can be more performant, since costly DOM operations can be avoided (e.g. first removing old nodes, and the adding new nodes) and the existing DOM nodes are updated to display the new data. For react and angular using the item index as the key uses “non-keyed” mode for those frameworks.
52+
53+
Depending on your requirements the “non-keyed” mode can be a performance gain or can cause severe problems so one must choose carefully the mode and check that the framework supports that mode.
54+
55+
Read more here: [https://www.stefankrause.net/wp/?p=342](https://www.stefankrause.net/wp/?p=342)
56+
4757
# 1 NEW: Run pre-built binaries for all frameworks
4858

4959
There are currently ~60 framework entries in this repository. Installing (and maintaining) those can be challenging, but here are simplified instructions how to get started.
@@ -298,6 +308,144 @@ After that you can check all results in [http://localhost:8080/webdriver-ts/tabl
298308

299309
## 4. Contributing a new implementation
300310

311+
## TL;DR
312+
![demo](https://github.com/dsvorc41/js-framework-benchmark/assets/20287188/91ae2d64-7362-4be8-b88f-e52637b33fa5)
313+
314+
1. Install all of the root-level dependencies
315+
1. `cd js-framework-benchmark/`
316+
1. `npm ci` or `npm i`
317+
2. Make a new directory for your desired framework, for example Fast framework: `mkdir /frameworks/keyed/fast`
318+
3. Set up your new directory in whatever way is appropriate for that framework, for example:
319+
1. Set up prettier, eslint, dependencies (i.e. `@microsoft/fast-element`) etc
320+
2. Create `index.html` in the root of your folder where your app will be served `touch /frameworks/keyed/fast/index.html`
321+
3. Note: your html file must use the global CSS styles `<link href="/css/currentStyle.css" rel="stylesheet" />`
322+
4. Serve the page - Test that your html page is loaded properly in the browser
323+
1. For example put `<h1>Hello World - Fast Framework</h1>` somewhere
324+
2. Run the server from the root directory: `npm start`
325+
3. Visit your page in the browser (URL follows the folder structure): `http://localhost:8080/frameworks/keyed/fast/index.html`
326+
4. Note: Its important to always start the server from the root, because that way you'll get access to global CSS that all apps must share
327+
5. Note 2: **AVOID SHADOW DOM** - if your framework relies on Shadow Dom (like Fast framework does), you should turn it off. Otherwise you won't get access to global CSS.
328+
5. Add the "action triggers" - buttons that all apps must have (see `frameworks/keyed/vanillajs/index.html`)
329+
1. Note: Action triggers are simply buttons that are used to run the benchmarks (adding rows, deleting rows, swapping them, etc). Those buttons can be static HTML, or you can render them dynamically (with JS) with your framework of choice
330+
2. Make sure your HTML elements have the same classes and structure as VanillaJS, otherwise benchmarks won't be able to find your elements on the page, and you will not get the global CSS (Bootstrap)
331+
3. Add the html example below and open the page. You should see nicely formatted elements on the page, like in the GIF image above.
332+
4. Example for action triggers
333+
```html
334+
<body>
335+
<div id="main">
336+
<div class="container">
337+
<div class="jumbotron">
338+
<div class="row">
339+
<div class="col-md-6">
340+
<h1>VanillaJS-"keyed"</h1>
341+
</div>
342+
<div class="col-md-6">
343+
<div class="row">
344+
<div class="col-sm-6 smallpad">
345+
<button
346+
type="button"
347+
class="btn btn-primary btn-block"
348+
id="run"
349+
>
350+
Create 1,000 rows
351+
</button>
352+
</div>
353+
<div class="col-sm-6 smallpad">
354+
<button
355+
type="button"
356+
class="btn btn-primary btn-block"
357+
id="runlots"
358+
>
359+
Create 10,000 rows
360+
</button>
361+
</div>
362+
<div class="col-sm-6 smallpad">
363+
<button
364+
type="button"
365+
class="btn btn-primary btn-block"
366+
id="add"
367+
>
368+
Append 1,000 rows
369+
</button>
370+
</div>
371+
<div class="col-sm-6 smallpad">
372+
<button
373+
type="button"
374+
class="btn btn-primary btn-block"
375+
id="update"
376+
>
377+
Update every 10th row
378+
</button>
379+
</div>
380+
<div class="col-sm-6 smallpad">
381+
<button
382+
type="button"
383+
class="btn btn-primary btn-block"
384+
id="clear"
385+
>
386+
Clear
387+
</button>
388+
</div>
389+
<div class="col-sm-6 smallpad">
390+
<button
391+
type="button"
392+
class="btn btn-primary btn-block"
393+
id="swaprows"
394+
>
395+
Swap Rows
396+
</button>
397+
</div>
398+
</div>
399+
</div>
400+
</div>
401+
</div>
402+
<table class="table table-hover table-striped test-data">
403+
<!-- your dynamic content should render here -->
404+
</table>
405+
</div>
406+
</div>
407+
</body>
408+
```
409+
6. Generate dummy data for rendering
410+
1. See `frameworks/keyed/fast/src/utils/build-dummy-data.ts` as an example
411+
2. Note: `id` is an important attribute and it must be initialized as `1`, and continuously incremented. The only time `id` resets back to `1` is when the page reloads - otherwise it should just keep incrementing each time a new row is created. Doing anything else will cause errors when benchmarks try to find elements with specific IDs. Trust me, I learned the hard way.
412+
7. . Your app needs to support several actions that correspond to "Action triggers" listed above. Here's an example from Fast framework `frameworks\keyed\fast\src\App.ts` and `frameworks\keyed\fast\src\components\Table.ts`:
413+
1. Code example:
414+
```typescript
415+
export class BenchmarkApp extends FASTElement {
416+
createOneThousandRows() {}
417+
createTenThousandRows() {}
418+
appendOneThousandRows() {}
419+
updateEveryTenthRowLabel() {}
420+
deleteAllRows() {}
421+
swapTwoRows() {}
422+
deleteSingleRow(rowId: number) {}
423+
}
424+
425+
export class Table extends FASTElement {
426+
selectRow(rowId: number) {}
427+
}
428+
```
429+
2. Note: your app doesn't need methods with the same name - you should write idiomatic code and follow the best practices of your framework of choice. The example above is just to give you an idea of which operations must be supported, but how you choose to implement those methods can be very different from one framework to the next.
430+
8. Manually testing your app - do this before you run the benchmarks
431+
1. Open your page and click on the buttons, make sure your app adds 1000 rows, then removes them, or swaps them, or adds/removes 10,000 rows.
432+
2. To do this, you'll probably need to watch your local files and compile them into some sort of a bundle, like `frameworks\keyed\fast\dist\bundle.js` which will be loaded through a script tag in your HTML file
433+
3. For example, in Fast folder we have webpack watching our files: ` "build-dev": "rimraf dist && webpack --config webpack.config.js --watch --mode=development",`
434+
4. That means we have two terminal tabs running
435+
1. One for the server from the root folder `npm start`
436+
2. And another in our local folder where webpack is watching the files
437+
9. Run the single benchmark for your framework
438+
1. Once you manually verified that everything works as expected, run a single benchmark and make sure all of the tests are running
439+
2. If you forgot something, one of the benchmarks will probably fail - for example it won't be able to find an element on the page or similar
440+
3. Keep the server in the root folder running `npm start`, and in another terminal tab, also from the root folder run `npm run bench -- --framework keyed/fast` (or whatever is your framework `keyed/react`, `keyed/angular`, etc.).
441+
4. The benchmark runner will open and close Chrome multiple times. The whole thing will take a couple of minutes.
442+
10. Optional: run the benchmark for VanillaJS as comparison
443+
1. ` npm run bench -- --framework keyed/vanillajs`
444+
11. Build the report
445+
1. `npm run results`
446+
12. Open the report in your browser (NOTE: the server must still be running if you want to see this page)
447+
1. `http://localhost:8080/webdriver-ts-results/table.html`
448+
301449
## 4.1 Building the app
302450

303451
For contributions it is basically sufficient to create a new directory for your framework that supports `npm install` and `npm run build-prod` and can be then opened in the browser. All other steps are optional. Let's simulate that by copying vanillajs.

frameworks/keyed/vanillajs/src/Main.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,6 @@ class Store {
4949
select(id) {
5050
this.selected = id;
5151
}
52-
hideAll() {
53-
this.backup = this.data;
54-
this.data = [];
55-
this.selected = null;
56-
}
57-
showAll() {
58-
this.data = this.backup;
59-
this.backup = null;
60-
this.selected = null;
61-
}
6252
runLots() {
6353
this.data = this.buildData(10000);
6454
this.selected = null;
@@ -115,16 +105,6 @@ class Main {
115105
//console.log("update");
116106
this.update();
117107
}
118-
else if (e.target.matches('#hideall')) {
119-
e.preventDefault();
120-
//console.log("hideAll");
121-
this.hideAll();
122-
}
123-
else if (e.target.matches('#showall')) {
124-
e.preventDefault();
125-
//console.log("showAll");
126-
this.showAll();
127-
}
128108
else if (e.target.matches('#runlots')) {
129109
e.preventDefault();
130110
//console.log("runLots");
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = {
2+
root: true,
3+
parser: '@typescript-eslint/parser',
4+
parserOptions: {
5+
ecmaVersion: 2019,
6+
sourceType: 'module',
7+
ecmaFeatures: {
8+
legacyDecorators: true
9+
}
10+
}
11+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"arrowParens": "avoid",
3+
"bracketSpacing": true,
4+
"htmlWhitespaceSensitivity": "css",
5+
"insertPragma": false,
6+
"jsxBracketSameLine": false,
7+
"jsxSingleQuote": false,
8+
"printWidth": 120,
9+
"requirePragma": false,
10+
"semi": true,
11+
"singleQuote": true,
12+
"tabWidth": 2,
13+
"trailingComma": "none",
14+
"useTabs": false
15+
}

frameworks/non-keyed/fast/index.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>Fast-"keyed"</title>
6+
<link href="/css/currentStyle.css" rel="stylesheet" />
7+
</head>
8+
<body>
9+
<div id="main">
10+
<div class="container">
11+
<benchmark-app></benchmark-app>
12+
<span class="preloadicon glyphicon glyphicon-remove" aria-hidden="true"></span>
13+
</div>
14+
</div>
15+
<script src="dist/bundle.js"></script>
16+
</body>
17+
</html>

0 commit comments

Comments
 (0)