Skip to content
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

perf: use swc to transform TS in jest #330

Merged
merged 1 commit into from
Dec 27, 2022

Conversation

deodad
Copy link
Member

@deodad deodad commented Dec 27, 2022

Motivation

Closes #314. Speed up yarn test by ~2x.

Change Summary

Replace ts-jest with @swc/jest to transform our TS files in Jest.

Merge Checklist

@socket-security
Copy link

socket-security bot commented Dec 27, 2022

Socket Security Pull Request Report

👍 No new dependency issues detected in pull request

Pull request report summary
Issue Status
Install scripts ✅ 0 issues
Native code ✅ 0 issues
Bin script confusion ✅ 0 issues
Bin script shell injection ✅ 0 issues
Unresolved require ✅ 0 issues
Invalid package.json ✅ 0 issues
HTTP dependency ✅ 0 issues
Git dependency ✅ 0 issues
Potential typo squat ✅ 0 issues
Known Malware ✅ 0 issues
Telemetry ✅ 0 issues
Protestware/Troll package ✅ 0 issues
Bot Commands

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of package-name@version specifiers. e.g. @SocketSecurity ignore foo@1.0.0 bar@2.4.2

Ignoring: @swc/core@1.3.24

Powered by socket.dev

@codecov
Copy link

codecov bot commented Dec 27, 2022

Codecov Report

Base: 80.92% // Head: 80.61% // Decreases project coverage by -0.30% ⚠️

Coverage data is based on head (2a7acce) compared to base (c7bc251).
Patch has no changes to coverable lines.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #330      +/-   ##
==========================================
- Coverage   80.92%   80.61%   -0.31%     
==========================================
  Files          65       65              
  Lines        5777     5691      -86     
  Branches     1014     1041      +27     
==========================================
- Hits         4675     4588      -87     
- Misses       1095     1096       +1     
  Partials        7        7              
Impacted Files Coverage Δ
src/flatbuffers/generated/message_generated.ts 78.46% <0.00%> (-1.02%) ⬇️
src/flatbuffers/generated/gossip_generated.ts 71.42% <0.00%> (-0.71%) ⬇️
...buffers/generated/name_registry_event_generated.ts 57.52% <0.00%> (-0.68%) ⬇️
src/eth/ethEventsProvider.ts 61.74% <0.00%> (-0.51%) ⬇️
...atbuffers/generated/id_registry_event_generated.ts 82.31% <0.00%> (-0.32%) ⬇️
src/flatbuffers/generated/rpc_generated.ts 65.85% <0.00%> (-0.18%) ⬇️
src/utils/hubErrors.ts 90.90% <0.00%> (ø)
src/network/p2p/node.ts 78.99% <0.00%> (ø)
src/rpc/client/index.ts 92.59% <0.00%> (ø)
src/storage/engine/index.ts 83.62% <0.00%> (ø)
... and 11 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@deodad deodad changed the title chore: use swc to transform source code in jest perf: use swc to transform TS in jest Dec 27, 2022
@deodad
Copy link
Member Author

deodad commented Dec 27, 2022

The security check that is failing is for the install script from @swc/core, here's what the script does:

It checks if corresponding optional dependencies for native binary is installed and can be loaded properly.
If it fails, it'll internally try to install @swc/wasm as fallback.

This alert can be ignored by replying with a comment starting @SocketSecurity ignore @swc/core@1.3.24

@deodad deodad marked this pull request as ready for review December 27, 2022 18:38
@varunsrin
Copy link
Member

I ran some benchmarks locally, and the improvement seems closer to ~ 15%, not 100%. I still think its worth merging in, but I want to make sure this discrepancy isn't the result of some other config issue before we do that.

I used hyperfine to benchmark, and here's the output when running yarn test from main and clearing the cache each time

➜  hub git:(main) ✗ hyperfine 'rm -rf build && yarn test'
Benchmark 1: rm -rf build && yarn test
  Time (mean ± σ):     12.751 s ±  0.262 s    [User: 60.905 s, System: 3.453 s]
  Range (min … max):   12.155 s … 13.006 s    10 runs

Here's the output when doing it on your branch:

➜  hub git:(ad/swc-build) ✗ hyperfine 'rm -rf build && yarn test'
Benchmark 1: rm -rf build && yarn test
  Time (mean ± σ):     11.166 s ±  0.222 s    [User: 40.538 s, System: 2.851 s]
  Range (min … max):   11.004 s … 11.657 s    10 runs

@deodad
Copy link
Member Author

deodad commented Dec 27, 2022

Jest has its own cache for transformed modules separate from ./build, what do you get w hyperfine 'yarn test --no-cache'?

ts-jest:

Benchmark 1: yarn test --no-cache
  Time (mean ± σ):     51.285 s ±  0.889 s    [User: 282.376 s, System: 15.140 s]
  Range (min … max):   50.079 s … 52.389 s    5 runs

swc:

Benchmark 1: rm -rf build && yarn test --no-cache
  Time (mean ± σ):     21.337 s ±  0.384 s    [User: 82.215 s, System: 7.419 s]
  Range (min … max):   20.936 s … 21.719 s    5 runs

@varunsrin
Copy link
Member

varunsrin commented Dec 27, 2022

That comes out much better, shows closer to a 40% improvement on an M1. I think its worth merging

✨  Done in 19.70s.
  Time (mean ± σ):     18.909 s ±  0.646 s    [User: 109.488 s, System: 6.586 s]
  Range (min … max):   17.801 s … 19.797 s    10 runs
✨  Done in 12.46s.
  Time (mean ± σ):     12.653 s ±  0.185 s    [User: 41.741 s, System: 3.459 s]
  Range (min … max):   12.454 s … 13.080 s    10 runs

@varunsrin
Copy link
Member

@SocketSecurity ignore @swc/core@1.3.24

@varunsrin varunsrin merged commit 5d99da1 into farcasterxyz:main Dec 27, 2022
@varunsrin varunsrin added the t-chore Miscellaneous improvements label Dec 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t-chore Miscellaneous improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

perf: use swc or esbuild toolchain to transpile code locally
2 participants