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

Faster initialization #138

Merged
merged 6 commits into from
Jul 27, 2023
Merged

Faster initialization #138

merged 6 commits into from
Jul 27, 2023

Conversation

gurgunday
Copy link
Member

@gurgunday gurgunday commented Jul 27, 2023

It doesn't amount to much, but I'm consistently seeing faster initialization results with a for loop instead of forEach. I tested the difference very simply by wrapping the whole plugin with console.time() and running the tests. With the for loop, the startup almost always takes less then 0.01ms, which otherwise does not happen on my machine

This PR also fixes a test, makes linting part of the test suite, adds the lint:fix script as well as @fastify/pre-commit

OLD

test/httpErrorsReply.test.js 1> default: 0.01ms
test/httpErrorsReply.test.js 1> default: 0.01ms
test/httpErrorsReply.test.js 1> default: 0.014ms
test/httpErrorsReply.test.js 1> default: 0.012ms
test/httpErrorsReply.test.js 1> default: 0.011ms
test/httpErrorsReply.test.js 1> default: 0.01ms
test/httpErrorsReply.test.js 1> default: 0.013ms
test/httpErrorsReply.test.js 1> default: 0.014ms
test/httpErrorsReply.test.js 1> default: 0.019ms
test/httpErrorsReply.test.js 1> default: 0.015ms
test/httpErrorsReply.test.js 1> default: 0.011ms
test/httpErrorsReply.test.js 1> default: 0.01ms
test/httpErrorsReply.test.js 1> default: 0.012ms
test/httpErrorsReply.test.js 1> default: 0.011ms
test/httpErrorsReply.test.js 1> default: 0.01ms
test/httpErrorsReply.test.js 1> default: 0.01ms
test/httpErrorsReply.test.js 1> default: 0.01ms
test/httpErrorsReply.test.js 1> default: 0.01ms
test/httpErrorsReply.test.js 1> default: 0.014ms
test/httpErrorsReply.test.js 1> default: 0.011ms
test/httpErrorsReply.test.js 1> default: 0.011ms
test/httpErrorsReply.test.js 1> default: 0.013ms
test/httpErrorsReply.test.js 1> default: 0.014ms
test/httpErrorsReply.test.js 1> default: 0.013ms
test/httpErrorsReply.test.js 1> default: 0.012ms

NEW

test/httpErrorsReply.test.js 1> default: 0.01ms
test/httpErrorsReply.test.js 1> default: 0.009ms
test/httpErrorsReply.test.js 1> default: 0.008ms
test/httpErrorsReply.test.js 1> default: 0.008ms
test/httpErrorsReply.test.js 1> default: 0.008ms
test/httpErrorsReply.test.js 1> default: 0.008ms
test/httpErrorsReply.test.js 1> default: 0.008ms
test/httpErrorsReply.test.js 1> default: 0.008ms
test/httpErrorsReply.test.js 1> default: 0.008ms
test/httpErrorsReply.test.js 1> default: 0.008ms
test/httpErrorsReply.test.js 1> default: 0.008ms
test/httpErrorsReply.test.js 1> default: 0.012ms
test/httpErrorsReply.test.js 1> default: 0.009ms
test/httpErrorsReply.test.js 1> default: 0.009ms
test/httpErrorsReply.test.js 1> default: 0.009ms
test/httpErrorsReply.test.js 1> default: 0.009ms
test/httpErrorsReply.test.js 1> default: 0.009ms

Checklist

@gurgunday gurgunday changed the title Faster init Faster initialization Jul 27, 2023
package.json Outdated Show resolved Hide resolved
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

@Eomm Eomm merged commit eef9653 into fastify:master Jul 27, 2023
15 checks passed
@gurgunday gurgunday deleted the faster-init branch July 27, 2023 13:23
@Uzlopak
Copy link
Contributor

Uzlopak commented Jul 27, 2023

Yes. Always avoid forEach map and co.

This pull request was closed.
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.

4 participants