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

perf(jsx): JSX performance improvement #444

Merged
merged 8 commits into from
Aug 1, 2022
Merged

Conversation

usualoma
Copy link
Member

@usualoma usualoma commented Aug 1, 2022

This PR fixes #439.

Changes

There are no changes to the external specification in this PR, and we can continue to stringify templates with (<p>text</p>).toString(). However, there are some changes in the internal structure.

jsx returns JSXNode instead of HtmlEscapedString

Previously, upon calling jsx, basic stringification was completed and an HtmlEscapedString object was returned, but with this PR, a data-wrapped JSXNode is returned upon calling jsx. The stringification is done at toString() call.

Discussion

With this PR, escape defined in utils/html is no longer used inside the hono repository. (Only escapeToBuffer is used.)

The escape function is fast enough and convenient for hono users to use in their applications, but depending on policy, it could be removed as unnecessary.

Benchmark

Hono x 173,197 ops/sec ±2.16% (93 runs sampled)
React x 84,569 ops/sec ±2.81% (91 runs sampled)
Preact x 61,307 ops/sec ±3.21% (86 runs sampled)
Nano x 16,871 ops/sec ±5.46% (78 runs sampled)
Fastest is Hono

@yusukebe
Copy link
Member

yusukebe commented Aug 1, 2022

Hi @usualoma !

Great! I confirmed that it also works on Bun.

The escape function is fast enough and convenient for hono users to use in their applications, but depending on policy, it could be removed as unnecessary.

Yes, I think it's better to remove utils/html. I'll do it another PR.

I'll merge this PR!

@yusukebe yusukebe merged commit 85cbf3e into honojs:main Aug 1, 2022
@usualoma usualoma deleted the perf-jsx branch August 1, 2022 23:23
@yusukebe yusukebe added the change label Aug 6, 2022
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.

JSX performance improvement
2 participants