-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark.html
More file actions
237 lines (230 loc) · 12.3 KB
/
Copy pathbenchmark.html
File metadata and controls
237 lines (230 loc) · 12.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>llselect + AngularJS - benchmark</title>
<link rel="stylesheet" href="../style.css">
<link rel="stylesheet" href="../../dist/themes/vanilla.css">
<!-- ui-select's bootstrap theme needs Bootstrap's own CSS. Demo-only CDN. -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.4.1/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ui-select@0.19.8/dist/select.min.css">
<style>
.bench-table { border-collapse: collapse; width: 100%; margin: 1rem 0; }
.bench-table th, .bench-table td { border: 1px solid #d5dae2; padding: 0.4rem 0.6rem; text-align: right; }
.bench-table th:first-child, .bench-table td:first-child { text-align: left; }
.bench-table small { color: #666; font-weight: normal; display: block; margin-top: 0.2rem; }
.bench-name { background: #eef3fb; font-weight: bold; white-space: nowrap; }
.bench-table td:first-child { max-width: 22rem; }
.bench-controls { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end; margin: 1rem 0; }
.bench-controls label { display: block; font-size: 0.85rem; color: #555; }
.bench-controls input { width: 7rem; padding: 0.3rem; font: inherit; }
.bench-best { background: #e6f6e6; font-weight: bold; }
/* The stage MUST be on-screen and laid out, and MUST NOT be a scroll
container. llselect refuses to open a trigger that is outside the layout
viewport OR clipped by a scroll ancestor (positioning.ts isAnchorHidden),
and it closes an open popup that later becomes clipped - and its popup
renders inside the mount, so an `overflow: auto` stage would clip that
too. A plain visible block avoids both. The measured widget is scrolled
into view first; the rest just sits there. */
#stage { width: 320px; margin: 1rem 0; }
#stage:empty { display: none; }
#playground { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: 1.5rem; margin: 1rem 0 2rem; }
#playground:empty { display: none; }
.try-box h4 { margin: 0 0 0.2rem; font-size: 1rem; }
.try-box small { color: #666; display: block; margin-bottom: 0.6rem; min-height: 2.4em; }
/* Each widget needs room below it for its own popup. */
.try-mount { min-height: 3rem; }
.model-panel { border-top: 2px solid #2456a6; padding-top: 0.8rem; margin-bottom: 2rem; }
.model-panel .out b { font-size: 1.1rem; }
.model-panel small { color: #888; }
</style>
</head>
<body>
<nav class="demo-nav">
<a href="../../">← Home</a>
<a href="../../api/">API</a>
<a href="../examples.html">Examples</a>
<a href="../benchmark.html">Benchmark</a>
<a href="../../angularjs/" class="current">AngularJS</a>
</nav>
<nav class="demo-subnav">
<span class="subnav-label"><svg viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M12,2.5L20.84,5.65L19.5,17.35L12,21.5L4.5,17.35L3.16,5.65L12,2.5M12,4.5L5,7L6.08,16.22L12,19.5L17.92,16.22L19,7L12,4.5M12,5.72L16.58,16H14.87L13.94,13.72H10.04L9.12,16H7.41L12,5.72M13.34,12.3L12,9.07L10.66,12.3H13.34Z"/></svg>AngularJS 1.x</span>
<a href="../../angularjs/">README</a>
<a href="../../angularjs/api.html">API</a>
<a href="examples.html">Examples</a>
<a href="benchmark.html" class="current">Benchmark</a>
</nav>
<h1>llselect + AngularJS 1.x - benchmark</h1>
<p>
Three ways to put a select in an AngularJS 1.x app, on the same data and the
same page. See <a href="../../angularjs/">angularjs/README.md</a> for what each one is.
</p>
<p>
The dataset is a real timezone picker: every IANA zone your browser knows
(<code>Intl.supportedValuesOf('timeZone')</code>, <span id="zone-count">...</span>
of them - the exact count is your browser's), built
<span id="widget-count">...</span> times over. A field real apps ship, and
already enough to make ui-select crawl.
</p>
<p>
Change the two numbers below and re-run to watch the ratios move (they are
also the <code>?items=</code> and <code>?widgets=</code> query parameters, so
a run is linkable). The incumbent <code><select ng-options></code> builds every
option up front, so its cost is linear in the item count; llselect builds the
list only on open, so its cost is flat. That is what widens the gap as the
list grows - not superlinearity. ui-select is the one that is genuinely
superlinear, and only per digest.
</p>
<div class="bench-controls">
<div>
<label for="in-items">Candidates per select</label>
<input id="in-items" type="number" min="1" max="20000" step="1">
</div>
<div>
<label for="in-widgets">Selects built</label>
<input id="in-widgets" type="number" min="1" max="500" step="1">
</div>
<button id="run">Run benchmark</button>
<button id="reset" type="button">Reset</button>
</div>
<div id="results"></div>
<div id="stage"></div>
<h2 id="try-heading" hidden>Try them yourself - one shared ng-model</h2>
<div id="try-note" hidden>
<p>
One live widget each, all four bound to the <b>same</b>
<code>ng-model</code>, on the same <span class="zone-count-inline">...</span>-zone
list. Two things to do with them.
</p>
<p>
<b>Feel the difference.</b> Open each one and type in its search box. The
table above says ui-select costs around 100x more per digest than
<code><llselect-single></code>; this is what that number actually
feels like. Raise the candidate count and re-run to widen it.
</p>
<p>
<b>Check the binding both ways.</b> Choosing in any one of them must move
all four, and the model is printed below. The two buttons are the
interesting part, because they ask each widget what it thinks "the same
item" means:
</p>
<ul>
<li>
<b>Set to items[3]</b> - the same object reference that is in the list.
Every widget resolves this.
</li>
<li>
<b>Set to a COPY of items[3]</b> - deep-equal, different reference. This
is what an app has after an HTTP round trip, or after
<code>angular.copy</code>. Watch the two booleans, not the text: every
widget still displays "the right thing", which is exactly what makes this
worth checking.
<br>
ui-select resolves its model with strict <code>===</code> on the
<code>modelMapper</code> (<code>uiSelectSingleDirective.js:38</code>) -
not <code>angular.equals</code>, and its <code>track by</code> does not
enter into it. So it cannot match the copy, and falls back to
<code>return inputValue</code>: it displays the copy, and
<code>$select.selected</code> is an object that is not in its own list.
The text looks right and the state is wrong.
<br>
<code><llselect-single></code> is given <code>track by i.id</code>,
which becomes llselect's <code>compareFn</code>, so it treats the copy as
the same item - the popup still marks the right row.
</li>
</ul>
</div>
<div id="playground"></div>
<div id="model-out"></div>
<h2>What the numbers mean</h2>
<ul>
<li>
<b>digest while open</b> is the interesting column. With the dropdown open,
ui-select's theme template runs
<code>ng-class="{active: $select.isActive(this), disabled: $select.isDisabled(this)}"</code>
on every row, every digest. Both functions do an
<code>indexOf</code> over the whole item list
(<code>uiSelectController.js:317</code> and <code>:358</code>), so the cost
is O(n^2) per digest. llselect has no watchers on the list at all, so a
digest does not touch it. Measured in microseconds because that is the unit
it lives in: reported in ms, the fastest contestant printed 0.00 and the
column said nothing.
</li>
<li>
<b><ui-llselect></b> is expected to land between the two: it fixes
the O(n^2) by using llselect's DOM, but ui-select's markup contract forces
one child scope plus one <code>$compile</code> link per row, which
<code><llselect-single></code> does not pay.
</li>
<li>
The second table is the acceptance question: putting the same
<code>validation="required"</code> on <code><llselect-single></code>
must not cost more than putting it on the <code><select ng-options></code>
it replaces. angular-validation is element-agnostic (it watches
<code>ctrl.$modelValue</code>), so the difference should be widget cost
only, not validation cost.
</li>
<li>
<b><select ng-options></b> is the incumbent baseline. Its dropdown is
an OS widget, so its open and filter are <b>n/a</b>, not a fake 0 - the
same rule <code>docs/llm/SPEC_BENCHMARK.md</code> applies to the native select
in the main benchmark. Its build and digest are real, and it renders every
option up front rather than lazily.
</li>
<li>
<b>build</b> creates <span id="widget-count-2">20</span> widgets over the
whole zone list each. llselect renders the
item list lazily (only on open), and so does ui-select
(<code>ng-if="$select.open"</code> on its rows), so this column is mostly
trigger cost.
</li>
</ul>
<h2>Honest limits of this page</h2>
<ul>
<li>One run, one browser, no warmup discipline. Read it as an order of magnitude, not a score - the ratios move by tens of percent between runs.</li>
<li>Each digest is timed as a batch of 200 and divided, not timed individually: browsers clamp <code>performance.now()</code> to 100us, which a single digest lands under. Timed one at a time, every contestant here reads 0.</li>
<li>All three are measured through <code>scope.$digest()</code> and synthetic clicks, not real input, so it is a lower bound on real perceived latency for all of them equally.</li>
<li>ui-select is loaded with its Bootstrap theme and Bootstrap's CSS; llselect uses its vanilla theme. Layout cost is not identical, and no attempt is made to equalize it.</li>
<li>The stage is on-screen and painted, because it has to be: llselect refuses to open a trigger that is off-screen or clipped (<code>positioning.ts</code> <code>isAnchorHidden</code>), so an off-screen stage would measure an open that never happened. Paint is therefore included, for everyone equally.</li>
</ul>
<script src="https://cdn.jsdelivr.net/npm/angular@1.8.3/angular.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/angular-sanitize@1.8.3/angular-sanitize.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/angular-translate@2.19.1/dist/angular-translate.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/angular-validation-ghiscoding@1.5.28/dist/angular-validation.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/ui-select@0.19.8/dist/select.min.js"></script>
<script src="../../dist/index.umd.js"></script>
<script src="../../angularjs/llselect-angularjs.js"></script>
<script src="../../angularjs/llselect-ui-select.js"></script>
<script src="benchmark.js"></script>
<script>
window.describeAngularBench()
// The dataset is built at load, so a CHANGED count needs a reload to take
// effect. Compare against what this run actually used - comparing query
// strings instead would reload even on a first click, where the query is
// empty but the values are simply the defaults.
document.getElementById('run').addEventListener('click', function () {
var items = Number(document.getElementById('in-items').value)
var widgets = Number(document.getElementById('in-widgets').value)
var live = window.angularBenchParams
if (items !== live.items || widgets !== live.widgets) {
location.search = '?items=' + items + '&widgets=' + widgets + '&autorun=1'
return
}
start()
})
document.getElementById('reset').addEventListener('click', function () {
location.search = ''
})
function start() {
window.runAngularBench(
document.getElementById('stage'),
document.getElementById('results'),
document.getElementById('playground'))
document.getElementById('try-heading').hidden = false
document.getElementById('try-note').hidden = false
}
if (new URLSearchParams(location.search).get('autorun')) { start() }
</script>
</body>
</html>