docs: add performance considerations section#6457
Conversation
jean-michelet
left a comment
There was a problem hiding this comment.
I'm not sure we should add recommendations at the application level, as it's difficult to be exhaustive and it could require frequent updates.
This document seems more like a set of general recommendations for deploying Fastify.
| See [Getting Started](./Getting-Started.md#serialize-data) and | ||
| [Validation and Serialization](../Reference/Validation-and-Serialization.md). | ||
|
|
||
| ### Serverless |
There was a problem hiding this comment.
This is not specific to Fastify.
Removed the serverless section as it contains general advice not specific to Fastify.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| - **Multiple route parameters**: Having routes with many parameters | ||
| (e.g., `/near/:lat-:lng/radius/:r`) can negatively affect performance. | ||
| Consider a single parameter approach for hot paths. | ||
| See [Routes](../Reference/Routes.md#routes). |
There was a problem hiding this comment.
This bullet links to "Routes#routes", but the guidance about multiple parameters in a single path segment is covered in the URL building portion of the Routes doc. Linking directly to that subsection (e.g., "#url-building") would better match the text here.
| See [Routes](../Reference/Routes.md#routes). | |
| See [Routes](../Reference/Routes.md#url-building). |
| ## Performance Considerations | ||
| <a id="performance"></a> | ||
|
|
||
| Fastify is designed for maximum performance, but certain patterns and features | ||
| can impact it. This section consolidates common causes of performance | ||
| degradation: | ||
|
|
||
| ### Route Configuration | ||
|
|
||
| - **Regular expression routes**: Using regex in route parameters | ||
| (e.g., `/:file(^\\d+).png`) is expensive. Prefer simple parameters when | ||
| possible. See [Routes](../Reference/Routes.md#routes). | ||
|
|
||
| - **Multiple route parameters**: Having routes with many parameters | ||
| (e.g., `/near/:lat-:lng/radius/:r`) can negatively affect performance. | ||
| Consider a single parameter approach for hot paths. | ||
| See [Routes](../Reference/Routes.md#routes). | ||
|
|
||
| - **Version constraints**: Using `Accept-Version` header matching can degrade | ||
| router performance. See [Routes](../Reference/Routes.md#version-constraints). | ||
|
|
||
| - **Asynchronous custom constraints**: Custom constraints that fetch data | ||
| from external sources (like databases) should be a last resort. | ||
| See [Routes](../Reference/Routes.md#asynchronous-custom-constraints). | ||
|
|
||
| ### Serialization | ||
|
|
||
| - **JSON serialization without schema**: Native JSON serialization is slow. | ||
| Define response schemas to speed up serialization by 2-3x. | ||
| See [Getting Started](./Getting-Started.md#serialize-data) and | ||
| [Validation and Serialization](../Reference/Validation-and-Serialization.md). | ||
|
|
There was a problem hiding this comment.
The PR description says this section also covers serverless/cold start considerations, but that content isn’t present in the added “Performance Considerations” section. Either add the serverless subsection (with links) or update the PR description to match the actual changes.
| - **Regular expression routes**: Using regex in route parameters | ||
| (e.g., `/:file(^\\d+).png`) is expensive. Prefer simple parameters when | ||
| possible. See [Routes](../Reference/Routes.md#routes). |
There was a problem hiding this comment.
This bullet points readers to the top of the Routes reference ("#routes"), but the performance note is specifically about regex routes in path parameters, which is documented under the URL building section. Consider linking directly to the relevant subsection anchor (e.g., "#url-building") to make the reference more actionable.
|
Don't heave strong opinions on this, if others agree let's go! |
Closes #4832
Adds a new "Performance Considerations" section to Recommendations.md that consolidates common causes of performance degradation scattered throughout the documentation.
Changes
Each item links to the relevant documentation for more details.