-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
579 lines (403 loc) · 14.2 KB
/
index.html
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
<!DOCTYPE html>
<html>
<head>
<title>Template</title>
<meta charset="utf-8" />
<meta
name="viewport"
content="user-scalable=no,initial-scale=1,maximum-scale=1,minimum-scale=1,width=device-width"
/>
<link rel="stylesheet" type="text/css" href="./css/quasar.min.css" />
<link rel="stylesheet" type="text/css" href="./css/pure-min.css" />
<link rel="stylesheet" type="text/css" href="./css/spaces.css" />
<link rel="stylesheet" type="text/css" href="./css/typo.css" />
<link rel="stylesheet" type="text/css" href="./css/devices.min.css" />
<link rel="stylesheet" type="text/css" href="./css/gh-fork-ribbon.css" />
<link rel="stylesheet" type="text/css" href="./css/nord-dark.css" />
<link rel="stylesheet" type="text/css" href="./css/nord-light.css" />
<link rel="stylesheet" type="text/css" href="./css/font-nord.css" />
<link rel="stylesheet" type="text/css" href="./css/bg-nord.css" />
<link rel="stylesheet" type="text/css" href="./css/font-open-color.css" />
<link rel="stylesheet" type="text/css" href="./css/bg-open-color.css" />
<link rel="stylesheet" type="text/css" href="./css/material-icons.css" />
<link rel="stylesheet" type="text/css" href="./css/abs-layout.css" />
<link rel="stylesheet" type="text/css" href="./css/border-layout.css" />
<link rel="stylesheet" type="text/css" href="./css/text-rect.css" />
<link rel="stylesheet" type="text/css" href="./css/text-circle.css" />
<link rel="stylesheet" type="text/css" href="./css/card.css" />
<link rel="stylesheet" type="text/css" href="./css/lines.css" />
<link rel="stylesheet" type="text/css" href="./css/filters.css" />
<link rel="stylesheet" type="text/css" href="./fonts/remixicon.css" />
<link rel="stylesheet" type="text/css" href="./css/style.css" />
</head>
<body>
<textarea id="source">
layout: true
class: typo, typo-selection
---
class: nord-light, center, middle
## One Scala Method
<small>Seven Years of Rewrites</small>
---
class: nord-light, center, middle
## `.subdomain`
---
class: nord-light
## scala-uri
- scala-uri a Scala URL Parser
- Used by
- Guardian homepage
- HMRC
- 0.1 released 19 Nov 2012
---
class: nord-light, center, middle
![subdomain issue](static/subdomain-issue.png)
---
class: nord-light
## Subdomain · First Implementation
```scala
val hostParts = host.split('.').toVector
def subdomain = hostParts.head
```
- Version `0.3.6`
---
class: nord-light, center, middle
## Job Done.
![mic drop](https://media.giphy.com/media/3o7qDSOvfaCO9b3MlO/giphy.gif)
---
class: nord-light
## First Implementation · Problems
<br>
```scala
scala> Url.parse("https://google.com").subdomain
res0: String = google
scala> Url.parse("http://127.0.0.1/index.html").subdomain
res1: String = 127
scala> Url.parse("https://console.aws.amazon.com").subdomain
res2: String = console
```
---
class: nord-light, center, middle
![dunno](https://media.giphy.com/media/y65VoOlimZaus/giphy.gif)
## What even is a Subdomain?
---
class: nord-light
## Subdomain · Definition
> A subdomain is a domain that is part of a larger domain.
> For example, `west.example.com` is a subdomain of the `example.com` domain,
> which in turn is a subdomain of the `com` top-level domain (TLD).
[Source: wikipedia](https://en.wikipedia.org/wiki/Subdomain)
---
class: nord-light
## Subdomain · Being Pragmatic
<br>
.center[![domain name](static/domain-name.png)]
- How do we drop the TLD + Domain Name?
---
class: nord-light
## Dropping the TLD
```scala
host.split('.').dropRight(2)
```
.center[![no](https://media.giphy.com/media/23BST5FQOc8k8/giphy.gif)]
- What about SLDs `.co.uk`? lower levels?
- So what's the algorithm?
---
class: nord-light, center, middle
![mild shock](https://media.giphy.com/media/PFwKHjOcIoVUc/giphy.gif)
## There is no algorithm
---
class: nord-light
## publicsuffix.org
> Since there was and remains no algorithmic method of finding the highest level at
> which a domain may be registered, the only method is to create a list.
> This is the aim of the Public Suffix List.
- Maintained by Mozilla Foundation
- Effective top-level domain (eTLD)
- Firefox/Chrome/Chromium/Opera/IE
---
class: nord-light
## publicsuffix.org
```sql
// ===BEGIN ICANN DOMAINS===
// ac : https://en.wikipedia.org/wiki/.ac
ac
com.ac
edu.ac
gov.ac
net.ac
mil.ac
org.ac
```
- Full List [public_suffix_list.dat](https://github.com/publicsuffix/list/blob/master/public_suffix_list.dat)
- Find the **longest** match against a list of suffixes
---
class: nord-light
## Trie
- Encoding `uk`, `hk`, `co.uk` and `ac.uk`
<br>
.mermaid[
<pre>
graph LR
root(( )) --> k((k)) --> u((u)) --> d1((.))
k --> h((h))
d1 --> o((o)) --> c1((c))
d1 --> a((a)) --> c2((c))
style root fill:#444,stroke:#444
style u fill:#ffdede,stroke:#d33,color:#d33
style h fill:#ffdede,stroke:#d33,color:#d33
style c1 fill:#ffdede,stroke:#d33,color:#d33
style c2 fill:#ffdede,stroke:#d33,color:#d33
</pre>
]
<br>
.center[
## www.google.co.uk
]
---
class: nord-light
## Trie · In Scala
<br>
<strong>
```scala
case class Trie(
children: Map[Char,Trie],
end: Boolean
)
```
</strong>
---
class: nord-light
## Trie · By Segment
- Encoding `uk`, `hk`, `co.uk` and `ac.uk`
<br>
.mermaid[
<pre>
graph LR
root(( )) --> uk((uk)) --> co((co))
root --> hk((hk))
uk --> ac((ac))
style root fill:#444,stroke:#444
style uk fill:#ffdede,stroke:#d33,color:#d33
style hk fill:#ffdede,stroke:#d33,color:#d33
style co fill:#ffdede,stroke:#d33,color:#d33
style ac fill:#ffdede,stroke:#d33,color:#d33
</pre>
]
<br>
.center[
## www.google.co.uk
]
---
class: nord-light
## Segment Trie · In Scala
<br>
<strong>
```scala
case class Trie(
children: Map[String,Trie],
end: Boolean
)
```
</strong>
---
class: nord-light
## Which Trie?
- Memory trade offs
- Fewer hops
- Reverse string vs segment split and reverse
- Benchmarks in a later slide!
---
class: nord-light
## Death by JSON
```json
{"c":{"்":{"c":{"ர":{"c":{"ூ":{"c":{"ப":{"c":{"்":{"c":{"ப":{"c":{"க":{"c":{"்":{"c":{"ங":
{"c":{"ி":{"c":{"ச":{"c":{},"e":true}},"e":false}},"e":false}},"e":false}},"e":false}},"e":
false}},"e":false}},"e":false}},"e":false}},"e":false}},"e":false},"ם":{"c":{"ו":{"c":{"ק":
{"c":{},"e":true}},"e":false}},"e":false},"e":{"c":{"e":{"c":{"e":{"c":{"i":{"c":{},"e":true
}},"e":false},".":{"c":{"e":{"c":{"i":{"c":{"f":{"c":{},"e":true}},"e":false}},"e":false},
"u":{"c":{"d":{"c":{"e":{"c":{},"e":true}},"e":false}},"e":false},"m":{"c":{"o":{"c":{"c":{
"c":{".":{"c":{"t":{"c":{"o":{"c":{"p":{"c":{"s":{"c":{"g":{"c":{"o":{"c":{"l":{"c":{"b":{
"c":{},"e":true}},"e":false}},"e":false}},"e":false}},"e":false}},"e":false}},"e":false}},
"e":false}},"e":false}},"e":true}},"e":false}},"e":false},"i":{"c":{"r":{"c":{"p":{"c":{},
"e":true}},"e":false}},"e":false},"v":{"c":{"o":{"c":{"g":{"c":{},"e":true}},"e":false}},"e"
:false},"b":{"c":{"i":{"c":{"l":{"c":{},"e":true}},"e":false}},"e":false},"g":{"c":{"r":{"c"
...
```
- Full JSON [public_suffix_trie.json](https://raw.githubusercontent.com/lemonlabsuk/scala-uri/1.4.x/jvm/src/main/resources/public_suffix_trie.json)
- Version `0.5.0`
---
class: nord-light
## Concerns
- Introduced a JSON Parsing dependency
- `0.5.x` and `1.x` - no Scala.js support
- [Poor GraalVM experience](https://github.com/lemonlabsuk/scala-uri/issues/22):
![graal vm](static/graal.png)
---
class: nord-light
## Code Gen!
- `2.0.0` let's replace that JSON with code
---
class: nord-light
## Code Gen?
```sql
[error] Error while emitting io/lemonlabs/uri/inet/PublicSuffixTrie$
[error] Method too large: io/lemonlabs/uri/inet/PublicSuffixTrie$.publicSuffixTrie ()Trie;
[error] one error found
```
.center[![sigh](https://media.giphy.com/media/wPOARRtwuFG0/giphy.gif)]
---
class: nord-light
## Code Gen?
```sql
[error] Error while emitting io/lemonlabs/uri/inet/PublicSuffixTrie$
[error] Class too large: io/lemonlabs/uri/inet/PublicSuffixTrie$
[error] one error found
```
.center[![cry](https://media.giphy.com/media/k61nOBRRBMxva/giphy.gif)]
---
class: nord-light
## Code Gen
```scala
package io.lemonlabs.uri.inet
object PublicSuffixTrie {
lazy val publicSuffixTrie = Trie(Map(
''்' -> _bcd.t,'ם' -> _5dd.t,'e' -> _65.t,'л' -> _43b.t,'販' -> _8ca9.t,'团' -> _56e2.t,
's' -> _73.t,'拿' -> _62ff.t,'्' -> _94d.t,'业' -> _4e1a.t,'你' -> _4f60.t,'б' -> _431.t,
'x' -> _78.t,'品' -> _54c1.t,'物' -> _7269.t,'و' -> _648.t,'山' -> _5c71.t,'府' -> _5e9c.t,
'站' -> _7ad9.t,'闻' -> _95fb.t,'ತ' -> _ca4.t,'ب' -> _628.t,'籍' -> _7c4d.t,'益' -> _76ca.t,
'尚' -> _5c1a.t,'线' -> _7ebf.t,'n' -> _6e.t,'ม' -> _e21.t,'动' -> _52a8.t,'な' -> _306a.t,
...
}
```
- 154k lines of Scala code
- Full code [PublicSuffixTrie.scala](https://raw.githubusercontent.com/lemonlabsuk/scala-uri/2.0.0/shared/src/main/scala/io/lemonlabs/uri/inet/PublicSuffixTrie.scala)
---
class: nord-light
## It worked!
<iframe width="100%" height="70%" src="https://lemonlabs.io/scala-uri-scalajs-example/index.html" allowfullscreen frameborder=”no” border=”0″ marginwidth=”0″ marginheight=”0″ scrolling=”yes” allowtransparency=”yes”></iframe>
---
class: nord-light
## Another issue
<br>
.center[![big scala.js file](static/big-scala-js-file.png)]
---
class: nord-light
## Let's Benchmark
- Trie (each node a character)
- Trie (each node a segment)
- and???
---
class: nord-light, center, middle
![short circuit scan](https://media.giphy.com/media/DwrnYsZCXspu8/giphy.gif)
## Scan the whole public suffix list
---
class: nord-light
## Set look-up
- Store public suffix list in a `Set`
- Lookup suffixes L to R
```scala
suffixes.contains("www.google.co.uk") false
suffixes.contains("google.co.uk") false
suffixes.contains("co.uk") true
```
---
class: nord-light
## Benchmarking Public Suffix Algorithms · List Size
<iframe width="100%" height="70%" src="https://lemonlabs.io/scala-uri-benchmarks/public-suffixes/suffix-list-size/" allowfullscreen frameborder=”no” border=”0″ marginwidth=”0″ marginheight=”0″ scrolling=”yes” allowtransparency=”yes”></iframe>
---
class: nord-light
## Benchmarking Public Suffix Algorithms · Segment Count
<iframe width="100%" height="70%" src="https://lemonlabs.io/scala-uri-benchmarks/public-suffixes/segment-count/" allowfullscreen frameborder=”no” border=”0″ marginwidth=”0″ marginheight=”0″ scrolling=”yes” allowtransparency=”yes”></iframe>
---
class: nord-light
## Today
- scala-uri `2.2.2`
- `Set` look-ups for public suffixes
- 1.4MB Scala.js build
---
class: nord-light, center, middle
## Thanks!
</textarea>
<script src="js/remark.min.js"></script>
<script src="js/vue.js"></script>
<script src="js/quasar.umd.min.js"></script>
<script src="js/mermaid.min.js"></script>
<script>
// 预处理:去掉每行开头的空格,否则超过2层锁紧的类会导致解析出BUG
var targetTextArea = document.getElementById("source");
var lines = targetTextArea.innerHTML.split("\n");
targetTextArea.innerHTML = lines.map(line => line.replace(/^(?!\s+[\-|0-9])\s+/, "")).join("\n");
var slideshow = remark.create({
ratio: "16:9", // window ratio
// arta, ascetic, dark, default, far, github, googlecode, idea,
// ir-black, magula, monokai, rainbow, solarized-dark, solarized-light,
// sunburst, tomorrow, tomorrow-night-blue, tomorrow-night-bright,
// tomorrow-night, tomorrow-night-eighties, vs, zenburn.
highlightStyle: "github",
highlightLines: true,
countIncrementalSlides: false, // whether the incremental content count as one page
//slideNumberFormat: "", // If this parameter is set to "", the page number is not displayed
navigation: {
scroll: false, // Page turning with mouse wheel is allowed
touch: true, // Is it allowed to scroll back and forth by clicking on the left or right side of the screen
click: false // Allow the mouse to click on the left or right side of the screen to turn back and forth
}
});
// 初始化 VUE
for (var el of document.querySelectorAll(".vue")) {
new Vue({
el: el
});
}
// 初始化可点击预览的卡片
var preview_win_cards = document.querySelectorAll(".preview-win");
for (var card of preview_win_cards) {
(clickedCard => {
clickedCard.addEventListener("click", e => {
var img = clickedCard.querySelector("img");
if (img) {
window.open(img.src);
}
});
})(card);
}
// 背景色变化兼容 F11 全屏
function isFullScreen() {
return window.fullScreen || (window.innerWidth == screen.width && window.innerHeight == screen.height);
}
window.addEventListener("resize", () => {
if (isFullScreen()) {
document.body.style["background-color"] = "#000";
} else {
document.body.style["background-color"] = "#d7d8d2";
}
});
// 初始化 mermaid
mermaid.mermaidAPI.initialize({
startOnLoad: false,
theme: "forest",
themeCSS:
".tick>text { font-size:26px; } .taskTextOutsideRight,.taskTextOutsideLeft { font-size:20px; } .titleText {font-size:30px;} .sectionTitle {font-size:20px;}",
gantt: {
fontSize: 26,
barHeight: 30,
useMaxWidth: false
}
});
var mermaidCmps = document.querySelectorAll(".mermaid");
for (var i = 0; i < mermaidCmps.length; i++) {
var mermaidCmp = mermaidCmps[i];
var insertSvg = function(svgCode, bindFunctions) {
mermaidCmp.innerHTML = svgCode;
};
var graphDefinition = "";
let pCmps = mermaidCmp.querySelectorAll("pre");
for (var pCmp of pCmps) {
graphDefinition += pCmp.textContent.replace(/\\n/g, "<br/>");
}
var graph = mermaid.mermaidAPI.render("graphDiv" + i, graphDefinition, insertSvg);
}
</script>
</body>
</html>