Skip to content

Improve encode speed by ~50% #8

Open
YetAnotherMinion wants to merge 1 commit intoveddan:masterfrom
ThinkAlexandria:master
Open

Improve encode speed by ~50% #8
YetAnotherMinion wants to merge 1 commit intoveddan:masterfrom
ThinkAlexandria:master

Conversation

@YetAnotherMinion
Copy link
Copy Markdown

Moved entity lookup into match arms instead of using a function that does a binary search in static array, then boxes up the result, and then immediately unboxes it in the match.

Before cargo bench

running 4 tests
test bench_decode_attribute ... bench:   2,585,276 ns/iter (+/- 1,174,543) = 93 MB/s
test bench_decode_minimal   ... bench:   1,314,817 ns/iter (+/- 793,375) = 89 MB/s
test bench_encode_attribute ... bench:   2,103,300 ns/iter (+/- 874,982) = 54 MB/s
test bench_encode_minimal   ... bench:   1,799,386 ns/iter (+/- 889,072) = 63 MB/s

test result: ok. 0 passed; 0 failed; 0 ignored; 4 measured; 0 filtered out

After cargo bench

running 4 tests
test bench_decode_attribute ... bench:   2,273,943 ns/iter (+/- 986,740) = 106 MB/s
test bench_decode_minimal   ... bench:   1,292,612 ns/iter (+/- 840,655) = 91 MB/s
test bench_encode_attribute ... bench:   1,528,778 ns/iter (+/- 725,928) = 74 MB/s
test bench_encode_minimal   ... bench:   1,177,384 ns/iter (+/- 560,557) = 96 MB/s

test result: ok. 0 passed; 0 failed; 0 ignored; 4 measured; 0 filtered out

…instead of doing binary search in static array
@YetAnotherMinion
Copy link
Copy Markdown
Author

Checking in, this repo looks dead. Do you need new maintainers?

@LuoZijun
Copy link
Copy Markdown

@YetAnotherMinion

谢谢你分享的经验,我稍微做了一些改进,这样就能支持解码更多的 HTML 转义字符,性能看起来似乎也还行。

Thank you for sharing the experience, I made a little bit of improvement, so that I can support decoding more HTML escape characters( HTML Character entity references ), performance seems to be OK.

-- From Bing Translate

benchmark:

test lexer::htmlentity::bench_escape_html_with_bytes   ... bench:     226,428 ns/iter (+/- 67,908) = 503 MB/s
test lexer::htmlentity::bench_escape_html_with_chars   ... bench:     258,850 ns/iter (+/- 42,165) = 440 MB/s
test lexer::htmlentity::bench_escape_html_with_str     ... bench:     231,982 ns/iter (+/- 87,126) = 491 MB/s
test lexer::htmlentity::bench_unescape_html_with_bytes ... bench:     284,332 ns/iter (+/- 39,198) = 409 MB/s
test lexer::htmlentity::bench_unescape_html_with_chars ... bench:     328,042 ns/iter (+/- 22,807) = 355 MB/s
test lexer::htmlentity::bench_unescape_html_with_str   ... bench:     287,491 ns/iter (+/- 42,134) = 405 MB/s

Repo: LuoZijun/es@b67338f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants