-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Avoid unnecessary function declarations and call in pretty-format #3962
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3962 +/- ##
==========================================
- Coverage 59.86% 59.84% -0.03%
==========================================
Files 196 196
Lines 6763 6758 -5
Branches 6 6
==========================================
- Hits 4049 4044 -5
Misses 2711 2711
Partials 3 3
Continue to review full report at Codecov.
|
This is great, thanks so much for optimizing the code here. How did you track this down, did you do some profiling? As for throwing an error: while technically a breaking change, the type of the Thanks for coming up with this PR! |
You’re welcome. Something didn’t feel right in the function when I thought about a code change to support alternative API discussed in #3518 (comment). You would laugh to see a scan of my Pooh Bear brain puzzling it out. The performance improvements are a side effect of making the package more correct and clear where it has been hard for me understand, so a wider range of people might contribute successfully in the future to keep up with ECMAScript and application-specific data types. When Jest turns 21 people can reasonably expect it to break some things, heh? |
…stjs#3962) * Avoid unnecessary function declarations and call in pretty-format * Add missing newline and quotes * Move throw into printPlugin
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Problem:
printPlugin
“hoists” theboundPrint
andboundIndent
declarations and therefore initializes the functions whether or not a plugin matches the value.prettyFormat
callscreateIndent
if any plugins exist instead of if some plugin matches the value. Because plugins always exist in Jest, the conditional logic to avoid creating indentation for basic values doesn’t save any time.Solution:
findPlugin
function.if
statement to callprintPlugin
only if a plugin matches the value.createIndent
for arg inprintPlugin
andprintComplexValue
function calls.Your review is especially wanted about the decision to throw an error if a plugin returns a non-string value. Am happy to revert that change if it’s a step in a wrong direction. Current logic quietly falls through to print the value as either basic or complex.
Interpretation of the following performance measurements:
P.S. The calls to
printPlugin
are nice example of not ignoring indentation in a diff, heh :)Test plan
Jest