-
Notifications
You must be signed in to change notification settings - Fork 160
Improve Perf #800
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
Merged
Merged
Improve Perf #800
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
eb88ced
remove useless call and import
conico974 f2bcf13
add test for next server
conico974 c50c133
refactor
conico974 f828165
add env var test & move test
conico974 d40bb77
lint
conico974 1217fa3
changeset
conico974 5b41907
handle preloading
conico974 d71afec
review
conico974 5b6d8d8
added some comment
conico974 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
"@opennextjs/aws": patch | ||
--- | ||
|
||
Some perf improvements : | ||
- Eliminate unnecessary runtime imports. | ||
- Refactor route preloading to be either on-demand or using waitUntil or at the start or during warmerEvent. | ||
- Add a global function to preload routes when needed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from "./patchEnvVar.js"; | ||
conico974 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
export * from "./patchNextServer.js"; | ||
export * from "./patchFetchCacheISR.js"; | ||
export * from "./patchFetchCacheWaitUntil.js"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { createPatchCode } from "../astCodePatcher.js"; | ||
import type { CodePatcher } from "../codePatcher"; | ||
|
||
export const envVarRuleCreator = (envVar: string, value: string) => ` | ||
rule: | ||
kind: member_expression | ||
pattern: process.env.${envVar} | ||
inside: | ||
kind: if_statement | ||
conico974 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
stopBy: end | ||
fix: | ||
'${value}' | ||
`; | ||
|
||
export const patchEnvVars: CodePatcher = { | ||
name: "patch-env-vars", | ||
patches: [ | ||
conico974 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
versions: ">=15.0.0", | ||
field: { | ||
pathFilter: /module\.compiled\.js$/, | ||
contentFilter: /process\.env\.NEXT_RUNTIME/, | ||
patchCode: createPatchCode(envVarRuleCreator("NEXT_RUNTIME", '"node"')), | ||
}, | ||
}, | ||
{ | ||
versions: ">=15.0.0", | ||
field: { | ||
pathFilter: | ||
/(module\.compiled|react\/index|react\/jsx-runtime|react-dom\/index)\.js$/, | ||
contentFilter: /process\.env\.NODE_ENV/, | ||
patchCode: createPatchCode( | ||
envVarRuleCreator("NODE_ENV", '"production"'), | ||
), | ||
}, | ||
}, | ||
{ | ||
versions: ">=15.0.0", | ||
field: { | ||
pathFilter: /module\.compiled\.js$/, | ||
contentFilter: /process\.env\.TURBOPACK/, | ||
patchCode: createPatchCode(envVarRuleCreator("TURBOPACK", "false")), | ||
}, | ||
}, | ||
], | ||
}; |
4 changes: 2 additions & 2 deletions
4
...ext/src/build/patch/patchFetchCacheISR.ts → ...build/patch/patches/patchFetchCacheISR.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...c/build/patch/patchFetchCacheWaitUntil.ts → ...patch/patches/patchFetchCacheWaitUntil.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
packages/open-next/src/build/patch/patches/patchNextServer.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { createPatchCode } from "../astCodePatcher.js"; | ||
import type { CodePatcher } from "../codePatcher.js"; | ||
|
||
export const minimalRule = ` | ||
conico974 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
rule: | ||
kind: member_expression | ||
pattern: process.env.NEXT_MINIMAL | ||
any: | ||
- inside: | ||
kind: parenthesized_expression | ||
stopBy: end | ||
inside: | ||
kind: if_statement | ||
any: | ||
- inside: | ||
kind: statement_block | ||
inside: | ||
kind: method_definition | ||
any: | ||
- has: {kind: property_identifier, field: name, regex: runEdgeFunction} | ||
- has: {kind: property_identifier, field: name, regex: runMiddleware} | ||
- has: {kind: property_identifier, field: name, regex: imageOptimizer} | ||
- has: | ||
kind: statement_block | ||
has: | ||
kind: expression_statement | ||
pattern: res.statusCode = 400; | ||
fix: | ||
'true' | ||
`; | ||
|
||
export const disablePreloadingRule = ` | ||
rule: | ||
kind: statement_block | ||
inside: | ||
kind: if_statement | ||
any: | ||
- has: | ||
kind: member_expression | ||
pattern: this.nextConfig.experimental.preloadEntriesOnStart | ||
stopBy: end | ||
- has: | ||
kind: binary_expression | ||
pattern: appDocumentPreloading === true | ||
stopBy: end | ||
fix: | ||
'{}' | ||
`; | ||
|
||
// This rule is mostly for splitted edge functions so that we don't try to match them on the other non edge functions | ||
export const removeMiddlewareManifestRule = ` | ||
rule: | ||
kind: statement_block | ||
inside: | ||
kind: method_definition | ||
has: | ||
kind: property_identifier | ||
regex: getMiddlewareManifest | ||
fix: | ||
'{return null;}' | ||
`; | ||
|
||
export const patchNextServer: CodePatcher = { | ||
name: "patch-next-server", | ||
patches: [ | ||
{ | ||
versions: ">=15.0.0", | ||
field: { | ||
pathFilter: /next-server\.(js)$/, | ||
contentFilter: /process\.env\.NEXT_MINIMAL/, | ||
patchCode: createPatchCode(minimalRule), | ||
}, | ||
}, | ||
{ | ||
versions: ">=15.0.0", | ||
field: { | ||
pathFilter: /next-server\.(js)$/, | ||
contentFilter: /this\.nextConfig\.experimental\.preloadEntriesOnStart/, | ||
patchCode: createPatchCode(disablePreloadingRule), | ||
}, | ||
}, | ||
{ | ||
versions: ">=15.0.0", | ||
field: { | ||
pathFilter: /next-server\.(js)$/, | ||
contentFilter: /getMiddlewareManifest/, | ||
patchCode: createPatchCode(removeMiddlewareManifestRule), | ||
}, | ||
}, | ||
], | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.