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

Add encodeEntities fast path for inputs that don't need anything replaced #194

Merged
merged 1 commit into from
Mar 27, 2021
Merged

Conversation

jviide
Copy link
Contributor

@jviide jviide commented Mar 27, 2021

This pull request attempts to optimize util.js's encodeEntities function. This happens by skipping the .replace(...) chain for inputs that contain no characters that should be replaced.

The benchmarks seem get a boost from this (Node v14.16.0, Linux, x86), especially the SearchResults one. Here are the npm run bench results before this change:

Text:
baseline x 80.883 ops/sec ±1.16 (67 runs sampled)
current x 94.593 ops/sec ±2.36 (73 runs sampled)

SearchResults:
baseline x 404.532 ops/sec ±2.42 (79 runs sampled)
current x 448.104 ops/sec ±2.61 (83 runs sampled)

And after this change:

Text:
baseline x 83.055 ops/sec ±1.54 (68 runs sampled)
current x 103.134 ops/sec ±1.95 (74 runs sampled)

SearchResults:
baseline x 453.03 ops/sec ±2.13 (84 runs sampled)
current x 648.997 ops/sec ±2.88 (83 runs sampled)

Copy link
Member

@andrewiggins andrewiggins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Niceee!!

Copy link
Member

@marvinhagemeister marvinhagemeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet 🙌

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.

3 participants