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

fix(html/parser): perf and fixes #6543

Merged
merged 22 commits into from Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
9ac37fd
perf(html/parser): reuse buffer
alexander-akait Nov 29, 2022
29feaee
perf(html/parser): reuse buffer
alexander-akait Nov 29, 2022
3ce5834
fix(html/parser): handle newlines in attributes
alexander-akait Nov 29, 2022
a1410bd
fix(html/parser): span for broken attributes
alexander-akait Nov 29, 2022
79a4fd5
refactor: code
alexander-akait Nov 29, 2022
59beed0
refactor: code
alexander-akait Nov 29, 2022
55ad452
perf(html/parser): reduce looping and memory usage
alexander-akait Nov 29, 2022
c557521
perf(html/parser): reduce looping and memory usage
alexander-akait Nov 30, 2022
8d86fc2
perf(html/parser): reduce memory usage
alexander-akait Nov 30, 2022
372e4bd
perf(html/parser): reduce memory usage
alexander-akait Nov 30, 2022
5078d73
perf(html/parser): reduce memory usage
alexander-akait Nov 30, 2022
fa6de10
perf(html/parser): reduce memory usage
alexander-akait Nov 30, 2022
a164fa8
perf(html/parser): reduce memory usage
alexander-akait Nov 30, 2022
5af2240
perf(html/parser): reduce memory usage
alexander-akait Nov 30, 2022
d7dc3c7
perf(html/parser): reduce memory usage
alexander-akait Nov 30, 2022
0faae5d
refactor: code
alexander-akait Nov 30, 2022
dd8fe8b
refactor: code
alexander-akait Nov 30, 2022
ef5f74e
refactor: code
alexander-akait Nov 30, 2022
a9ada6f
refactor: avoid more buffers
alexander-akait Nov 30, 2022
072b114
fix: increase default buffer
alexander-akait Nov 30, 2022
44e428a
perf: improve
alexander-akait Nov 30, 2022
3b846ad
Merge branch 'main' into perf-html-parser
swc-bot Dec 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1,302 changes: 661 additions & 641 deletions crates/swc_html_parser/src/lexer/mod.rs

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions crates/swc_html_parser/tests/fixture/text/cr/dom.rust-debug
Expand Up @@ -67,3 +67,25 @@
}

"
| "
"
| <div>
| test="test

test

test"
| "
"
| <div>
| test="

test

test

test

"
| "
"
2 changes: 1 addition & 1 deletion crates/swc_html_parser/tests/fixture/text/cr/input.html
@@ -1 +1 @@
<!doctypehtml>Text<div>Text</div><div> Text</div><div> Text Text</div><div>Text Text</div><divtest="test"></div><divdata-q="test"></div><divdata-q='test'></div><divdata-q=test></div><style>.color { color: red; <!-- Test -->}</style>
<!doctypehtml>Text<div>Text</div><div> Text</div><div> Text Text</div><div>Text Text</div><divtest="test"></div><divdata-q="test"></div><divdata-q='test'></div><divdata-q=test></div><style>.color { color: red; <!-- Test -->}</style><div test="testtesttest"></div><div test="testtesttest"></div>
Expand Down
90 changes: 89 additions & 1 deletion crates/swc_html_parser/tests/fixture/text/cr/output.json
Expand Up @@ -2,7 +2,7 @@
"type": "Document",
"span": {
"start": 1,
"end": 305,
"end": 382,
"ctxt": 0
},
"mode": "no-quirks",
Expand Down Expand Up @@ -429,6 +429,94 @@
],
"content": null,
"isSelfClosing": false
},
{
"type": "Text",
"span": {
"start": 305,
"end": 306,
"ctxt": 0
},
"data": "\n",
"raw": "\r"
},
{
"type": "Element",
"span": {
"start": 306,
"end": 341,
"ctxt": 0
},
"tagName": "div",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [
{
"type": "Attribute",
"span": {
"start": 311,
"end": 334,
"ctxt": 0
},
"namespace": null,
"prefix": null,
"name": "test",
"rawName": "test",
"value": "test\n\ntest\n\ntest",
"rawValue": "\"test\r\rtest\r\rtest\""
}
],
"children": [],
"content": null,
"isSelfClosing": false
},
{
"type": "Text",
"span": {
"start": 341,
"end": 342,
"ctxt": 0
},
"data": "\n",
"raw": "\r"
},
{
"type": "Element",
"span": {
"start": 342,
"end": 381,
"ctxt": 0
},
"tagName": "div",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [
{
"type": "Attribute",
"span": {
"start": 347,
"end": 374,
"ctxt": 0
},
"namespace": null,
"prefix": null,
"name": "test",
"rawName": "test",
"value": "\n\ntest\n\ntest\n\ntest\n\n",
"rawValue": "\"\r\rtest\r\rtest\r\rtest\r\r\""
}
],
"children": [],
"content": null,
"isSelfClosing": false
},
{
"type": "Text",
"span": {
"start": 381,
"end": 382,
"ctxt": 0
},
"data": "\n",
"raw": "\r"
}
],
"content": null,
Expand Down
196 changes: 134 additions & 62 deletions crates/swc_html_parser/tests/fixture/text/cr/span.rust-debug

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions crates/swc_html_parser/tests/fixture/text/lf/dom.rust-debug
Expand Up @@ -67,3 +67,25 @@
}

"
| "
"
| <div>
| test="test

test

test"
| "
"
| <div>
| test="

test

test

test

"
| "
"
16 changes: 15 additions & 1 deletion crates/swc_html_parser/tests/fixture/text/lf/input.html
Expand Up @@ -52,4 +52,18 @@
<!-- Test -->
}

</style>
</style>
<div test="test

test

test"></div>
<div test="

test

test

test

"></div>
90 changes: 89 additions & 1 deletion crates/swc_html_parser/tests/fixture/text/lf/output.json
Expand Up @@ -2,7 +2,7 @@
"type": "Document",
"span": {
"start": 1,
"end": 305,
"end": 382,
"ctxt": 0
},
"mode": "no-quirks",
Expand Down Expand Up @@ -429,6 +429,94 @@
],
"content": null,
"isSelfClosing": false
},
{
"type": "Text",
"span": {
"start": 305,
"end": 306,
"ctxt": 0
},
"data": "\n",
"raw": "\n"
},
{
"type": "Element",
"span": {
"start": 306,
"end": 341,
"ctxt": 0
},
"tagName": "div",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [
{
"type": "Attribute",
"span": {
"start": 311,
"end": 334,
"ctxt": 0
},
"namespace": null,
"prefix": null,
"name": "test",
"rawName": "test",
"value": "test\n\ntest\n\ntest",
"rawValue": "\"test\n\ntest\n\ntest\""
}
],
"children": [],
"content": null,
"isSelfClosing": false
},
{
"type": "Text",
"span": {
"start": 341,
"end": 342,
"ctxt": 0
},
"data": "\n",
"raw": "\n"
},
{
"type": "Element",
"span": {
"start": 342,
"end": 381,
"ctxt": 0
},
"tagName": "div",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [
{
"type": "Attribute",
"span": {
"start": 347,
"end": 374,
"ctxt": 0
},
"namespace": null,
"prefix": null,
"name": "test",
"rawName": "test",
"value": "\n\ntest\n\ntest\n\ntest\n\n",
"rawValue": "\"\n\ntest\n\ntest\n\ntest\n\n\""
}
],
"children": [],
"content": null,
"isSelfClosing": false
},
{
"type": "Text",
"span": {
"start": 381,
"end": 382,
"ctxt": 0
},
"data": "\n",
"raw": "\n"
}
],
"content": null,
Expand Down