-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: improve vi.mock performance (#2594)
- Loading branch information
1 parent
c8e6fb6
commit 09d1989
Showing
3 changed files
with
77 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
interface ErrorOptions { | ||
message?: string | ||
stackTraceLimit?: number | ||
} | ||
|
||
/** | ||
* Get original stacktrace without source map support the most performant way. | ||
* - Create only 1 stack frame. | ||
* - Rewrite prepareStackTrace to bypass "support-stack-trace" (usually takes ~250ms). | ||
*/ | ||
export function createSimpleStackTrace(options?: ErrorOptions) { | ||
const { message = 'error', stackTraceLimit = 1 } = options || {} | ||
const limit = Error.stackTraceLimit | ||
const prepareStackTrace = Error.prepareStackTrace | ||
Error.stackTraceLimit = stackTraceLimit | ||
Error.prepareStackTrace = e => e.stack | ||
const err = new Error(message) | ||
const stackTrace = err.stack || '' | ||
Error.prepareStackTrace = prepareStackTrace | ||
Error.stackTraceLimit = limit | ||
return stackTrace | ||
} |
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