-
Notifications
You must be signed in to change notification settings - Fork 1.7k
perf: avoid await import for code that's guaranteed to execute
#8086
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,10 @@ | ||
| import type rfdcT from "rfdc"; | ||
| import rfdc from "rfdc"; | ||
|
|
||
| import { isObject } from "../lang.js"; | ||
|
|
||
| let clone: ReturnType<typeof rfdcT> | null = null; | ||
| export async function getDeepCloneFunction(): Promise<<T>(input: T) => T> { | ||
| const { default: rfdc } = await import("rfdc"); | ||
|
|
||
| if (clone === null) { | ||
| clone = rfdc(); | ||
| } | ||
| const clone = rfdc(); | ||
|
|
||
| export function getDeepCloneFunction(): <T>(input: T) => T { | ||
| return clone; | ||
|
Comment on lines
+1
to
8
|
||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,10 +10,8 @@ import { | |
| * @param value The value to clone. | ||
| * @returns The deep clone of the provided value. | ||
| */ | ||
| export async function deepClone<T>(value: T): Promise<T> { | ||
| const _deepClone = await getDeepCloneFunction(); | ||
|
|
||
| return _deepClone<T>(value); | ||
| export function deepClone<T>(value: T): T { | ||
| return getDeepCloneFunction()<T>(value); | ||
| } | ||
|
Comment on lines
+13
to
15
|
||
|
|
||
| /** | ||
|
|
||
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.
Switching from a dynamic import to a static import here means the signer implementation (and its transitive deps like
ethers) will be loaded as soon as this module is evaluated, even in flows that never callgetSigner/getSigners. If the goal is to remove per-callawait import(...)overhead but keep lazy loading, consider caching the imported module/class the first timegetSigneris called (lazy + cached) rather than importing it unconditionally at top-level.