Unverified Commit 9dad4cd9 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Don't parse default postponedsizelimit (#89906)

## For Maintainers

### What?

Optimize the `parseMaxPostponedStateSize` function by using a
pre-calculated byte value for the default size limit instead of parsing
it each time.

### Why?

This optimization improves performance (though it's a very small impact)
since `parseMaxPostponedStateSize` is in the hot path for rendering. By
using a pre-calculated constant value for the default case, we avoid
unnecessary parsing operations.

### How?

- Added a constant `DEFAULT_MAX_POSTPONED_STATE_SIZE_BYTES` with the
pre-calculated value of 100MB in bytes (104,857,600)
- Modified `parseMaxPostponedStateSize` to return the pre-calculated
constant when no size is provided
- Only call `parseSizeLimit` when a custom size is specified
parent 9e1cc736
...@@ -2,6 +2,9 @@ import type { SizeLimit } from '../../types' ...@@ -2,6 +2,9 @@ import type { SizeLimit } from '../../types'
export const DEFAULT_MAX_POSTPONED_STATE_SIZE: SizeLimit = '100 MB' export const DEFAULT_MAX_POSTPONED_STATE_SIZE: SizeLimit = '100 MB'
// 100MB in bytes. Not using the parseSizeLimit for performance as parseMaxPostponedStateSize is in the hot path for rendering.
const DEFAULT_MAX_POSTPONED_STATE_SIZE_BYTES = 104_857_600
function parseSizeLimit(size: SizeLimit): number | undefined { function parseSizeLimit(size: SizeLimit): number | undefined {
const bytes = ( const bytes = (
require('next/dist/compiled/bytes') as typeof import('next/dist/compiled/bytes') require('next/dist/compiled/bytes') as typeof import('next/dist/compiled/bytes')
...@@ -18,5 +21,8 @@ function parseSizeLimit(size: SizeLimit): number | undefined { ...@@ -18,5 +21,8 @@ function parseSizeLimit(size: SizeLimit): number | undefined {
export function parseMaxPostponedStateSize( export function parseMaxPostponedStateSize(
size: SizeLimit | undefined size: SizeLimit | undefined
): number | undefined { ): number | undefined {
return parseSizeLimit(size ?? DEFAULT_MAX_POSTPONED_STATE_SIZE) if (!size) {
return DEFAULT_MAX_POSTPONED_STATE_SIZE_BYTES
}
return parseSizeLimit(size)
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment