-
-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: strip source map when unused (#374)
- Loading branch information
1 parent
c6133e5
commit 0e83db7
Showing
6 changed files
with
76 additions
and
44 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 |
---|---|---|
@@ -1,36 +1,37 @@ | ||
export const time = <Argument>( | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export const time = <T extends (...args: any[]) => unknown>( | ||
name: string, | ||
_function: (...args: Argument[]) => unknown, | ||
) => function ( | ||
this: unknown, | ||
...args: Argument[] | ||
) { | ||
const timeStart = Date.now(); | ||
const logTimeElapsed = () => { | ||
const elapsed = Date.now() - timeStart; | ||
_function: T, | ||
threshold = 100, | ||
): T => function ( | ||
this: unknown, | ||
...args: Parameters<T> | ||
) { | ||
const timeStart = Date.now(); | ||
const logTimeElapsed = () => { | ||
const elapsed = Date.now() - timeStart; | ||
|
||
if (elapsed > 10) { | ||
// console.log({ | ||
// name, | ||
// args, | ||
// elapsed, | ||
// }); | ||
} | ||
}; | ||
if (elapsed > threshold) { | ||
console.log(name, { | ||
args, | ||
elapsed, | ||
}); | ||
} | ||
}; | ||
|
||
const result = Reflect.apply(_function, this, args); | ||
if ( | ||
result | ||
const result = Reflect.apply(_function, this, args); | ||
if ( | ||
result | ||
&& typeof result === 'object' | ||
&& 'then' in result | ||
) { | ||
(result as Promise<unknown>).then( | ||
logTimeElapsed, | ||
// Ignore error in this chain | ||
() => {}, | ||
); | ||
} else { | ||
logTimeElapsed(); | ||
} | ||
return result; | ||
}; | ||
) { | ||
(result as Promise<unknown>).then( | ||
logTimeElapsed, | ||
// Ignore error in this chain | ||
() => {}, | ||
); | ||
} else { | ||
logTimeElapsed(); | ||
} | ||
return result; | ||
} as T; |
This file contains 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