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

chore: performance improvement on asStringSmall #688

Merged
merged 1 commit into from
Mar 10, 2024
Merged

chore: performance improvement on asStringSmall #688

merged 1 commit into from
Mar 10, 2024

Conversation

nigrosimone
Copy link
Contributor

Comparing more values in a single if statement has a little performance hit instead of make multiple if statement. In general, combining multiple comparisons into one if statement might result in slightly better performance due to reduced overhead from evaluating conditions and executing multiple control flow structures. This is because combining conditions can reduce the number of times the JavaScript engine has to evaluate expressions and jump between different parts of the code.

benchmark (master VS PR)

short string............................................. x 16,634,103 ops/sec ±2.06% (182 runs sampled)

short string............................................. x 18,920,179 ops/sec ±1.07% (184 runs sampled)

PR seems better!

Checklist

Copy link
Contributor

@Uzlopak Uzlopak left a comment

Choose a reason for hiding this comment

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

makes sense

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@mcollina mcollina merged commit 64e163d into fastify:master Mar 10, 2024
19 checks passed
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.

None yet

3 participants