Improve performance of SearchSource.findMatchingTests by 15%#8184
Conversation
Codecov Report
@@ Coverage Diff @@
## master #8184 +/- ##
==========================================
- Coverage 62.32% 62.32% -0.01%
==========================================
Files 265 265
Lines 10469 10465 -4
Branches 2545 2541 -4
==========================================
- Hits 6525 6522 -3
Misses 3361 3361
+ Partials 583 582 -1
Continue to review full report at Codecov.
|
SimenB
left a comment
There was a problem hiding this comment.
nice! I thought the code looked weird when I migrated this to TS, makes sense to use an array instead here
(changelog)
thymikee
left a comment
There was a problem hiding this comment.
Sweet! Left some minor comments. Missing changelog
|
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
This PR is a 15% performance improvement for
SearchSource.findMatchingTests. I benchmarked a test data set of 300k files at 975ms~ with the current code. The same search pattern now executes in 830ms~.At Facebook, this means that for the common use case of triggering
jest MyFileName, Jest will launch >100ms faster. Sometimes you have to take the small wins. :)I optimized this by looking for inefficiencies in code that is called for every file. In this case:
Object.keysfor thestatsobject every time. Not efficient.I refactored away the issues by adapting the data structures to better fit the way they are being used. Since our stat filters are optional and we want to iterate them, they make more sense as an array. I maintained full type safety.
Test plan