Thanks to visit codestin.com
Credit goes to github.com

Skip to content

docs: add performance considerations section#6457

Open
ismaildasci wants to merge 2 commits into
fastify:mainfrom
ismaildasci:docs/performance-considerations
Open

docs: add performance considerations section#6457
ismaildasci wants to merge 2 commits into
fastify:mainfrom
ismaildasci:docs/performance-considerations

Conversation

@ismaildasci

Copy link
Copy Markdown

Closes #4832

Adds a new "Performance Considerations" section to Recommendations.md that consolidates common causes of performance degradation scattered throughout the documentation.

Changes

  • Added table of contents entry for the new section
  • Added Performance Considerations section covering:
    • Route configuration (regex routes, multiple parameters, version constraints, async constraints)
    • Serialization (JSON serialization without schema)
    • Serverless (application size impact on cold starts)

Each item links to the relevant documentation for more details.

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Jan 18, 2026

@jean-michelet jean-michelet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Comment thread docs/Guides/Recommendations.md Outdated
See [Getting Started](./Getting-Started.md#serialize-data) and
[Validation and Serialization](../Reference/Validation-and-Serialization.md).

### Serverless

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is not specific to Fastify.

Removed the serverless section as it contains general advice
not specific to Fastify.

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@Fdawgs Fdawgs requested review from Copilot and jean-michelet March 7, 2026 08:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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).

Copilot AI Mar 7, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Suggested change
See [Routes](../Reference/Routes.md#routes).
See [Routes](../Reference/Routes.md#url-building).

Copilot uses AI. Check for mistakes.
Comment on lines +356 to +387
## 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).

Copilot AI Mar 7, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +365 to +367
- **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).

Copilot AI Mar 7, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
@jean-michelet

Copy link
Copy Markdown
Member

@Fdawgs

Don't heave strong opinions on this, if others agree let's go!

@Fdawgs Fdawgs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Conflicting with #6520

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Causes of degradation

6 participants