-
-
Notifications
You must be signed in to change notification settings - Fork 87
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
refactor(index): async flow control #405
Conversation
It's impressive hom much change │ Stat │ 2.5% │ 50% │ 97.5% │ 99% │ Avg │ Stdev │ Max │
├─────────┼────────┼────────┼────────┼────────┼───────────┼──────────┼────────┤
│ Latency │ 334 ms │ 350 ms │ 395 ms │ 502 ms │ 354.97 ms │ 30.05 ms │ 730 ms │ I'm curious |
@multivoltage This is a MacBook Air (M1, 2020) - and it doesn't even have a cooling fan! The M-series IO is insane. Regarding the Looking further into it is very interesting though - because Take a look at the results when the benchmark command
This gives me the idea of pre-caching the files in |
716b5c0
to
8fdce42
Compare
More benchmarks with #407 merged in:
|
8fdce42
to
74d87a0
Compare
Just pushed some light refactoring made possible by the async flow control changes - for some big performance gains! BenchmarksNode 16
That's +35% for the existing benchmark :) Node 20
|
This looks pretty good to me! |
- viewDecorator: remove spurious defined check - decorateReply: capitalize getHeader check - minify definition: null instead of false when not enabled - getRequestedPath: remove spurious optional chaining - use optional chaining for layout checks - avoid “assign to `x` then return `x`” pattern
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
@Uzlopak ptal |
Pushed a regression test as this refactoring incidentally solves #404 For reference, if the added test is added to |
Closes fastify#404 Add a regression test for previously incorrect behavior: when the `fastify` instance had an `onError` added, errors thrown by renderer resulted in server crash.
54ae166
to
28a562e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blocking
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
wdyt? |
We need this |
@Uzlopak lgtm, I will put add the function inside the plugin closure for consistency |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Can we have some new benchmarks, please ;)
If we merge #408 we could get high level benchmarks just by adding a tag 😝 Here's the full output (Node v20.11.1, macOS, M1):
|
Awesome. @gurgunday |
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [@fastify/view](https://togithub.com/fastify/point-of-view) | [`8.2.0` -> `9.0.0`](https://renovatebot.com/diffs/npm/@fastify%2fview/8.2.0/9.0.0) | [![age](https://developer.mend.io/api/mc/badges/age/npm/@fastify%2fview/9.0.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@fastify%2fview/9.0.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@fastify%2fview/8.2.0/9.0.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@fastify%2fview/8.2.0/9.0.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>fastify/point-of-view (@​fastify/view)</summary> ### [`v9.0.0`](https://togithub.com/fastify/point-of-view/releases/tag/v9.0.0) [Compare Source](https://togithub.com/fastify/point-of-view/compare/v8.2.0...v9.0.0) #### What's Changed - chore(package): explicitly declare js module type by [@​Fdawgs](https://togithub.com/Fdawgs) in [https://github.com/fastify/point-of-view/pull/398](https://togithub.com/fastify/point-of-view/pull/398) - test(eta): replace `typeof` undefined check by [@​Fdawgs](https://togithub.com/Fdawgs) in [https://github.com/fastify/point-of-view/pull/400](https://togithub.com/fastify/point-of-view/pull/400) - build(deps-dev): bump tsd from 0.29.0 to 0.30.0 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/fastify/point-of-view/pull/401](https://togithub.com/fastify/point-of-view/pull/401) - chore(.gitignore): add .tap/ dir by [@​Fdawgs](https://togithub.com/Fdawgs) in [https://github.com/fastify/point-of-view/pull/403](https://togithub.com/fastify/point-of-view/pull/403) - chore(.prettierignore): add by [@​mweberxyz](https://togithub.com/mweberxyz) in [https://github.com/fastify/point-of-view/pull/406](https://togithub.com/fastify/point-of-view/pull/406) - chore: add benchmarking script, additional benchmarks by [@​mweberxyz](https://togithub.com/mweberxyz) in [https://github.com/fastify/point-of-view/pull/407](https://togithub.com/fastify/point-of-view/pull/407) - build(deps-dev): bump delay from 5.0.0 to 6.0.0 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/fastify/point-of-view/pull/409](https://togithub.com/fastify/point-of-view/pull/409) - chore(benchmark): remove `delay` dependency by [@​mweberxyz](https://togithub.com/mweberxyz) in [https://github.com/fastify/point-of-view/pull/410](https://togithub.com/fastify/point-of-view/pull/410) - refactor(index): async flow control by [@​mweberxyz](https://togithub.com/mweberxyz) in [https://github.com/fastify/point-of-view/pull/405](https://togithub.com/fastify/point-of-view/pull/405) #### New Contributors - [@​mweberxyz](https://togithub.com/mweberxyz) made their first contribution in [https://github.com/fastify/point-of-view/pull/406](https://togithub.com/fastify/point-of-view/pull/406) **Full Changelog**: fastify/point-of-view@v8.2.0...v9.0.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - "on sunday" in timezone Asia/Shanghai, Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/PKUHPC/SCOW). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yMDAuMCIsInVwZGF0ZWRJblZlciI6IjM3LjIwMC4wIiwidGFyZ2V0QnJhbmNoIjoibWFzdGVyIn0=--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This reverts commit 235f588.
The goal of this commit is to modernize flow control throughout the plugin, converting callback-driven architecture to async-await.
As much as possible, the original flow of the code was kept intact, though a fair amount of error handling was removed, and the errors simply get thrown up to the renderer callers.
Some duplicate logic was factored up, namely all calls to
this.header
andthis.send
have been factored up into the reply decorator itself and out of the individual renderers.Edit: Additional commits factored up minification and page not defined checks out of the individual renderers as well.
Big thanks to @multivoltage for earlier work.
Benchmarks
master
on my machine (Node 16 on M1)and here's the result of this branch:
So we potentially have a slight regression at this point, but it seems to be within run-to-run variance. Working further from here, I've managed to get up into the 100k req/s averages with additional refactoring, but wanted to stop here and get this PR up before going any further, so the (hopeful) increase in code maintainability can be weighed versus the slight hit to performance.
Here's an
express.js
benchmark on my machine just for comparisons sake:Checklist
npm run test
and the Code of conduct
Closes #404