-
Notifications
You must be signed in to change notification settings - Fork 44
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(ramda): Use individual imports #79
Conversation
Import directly the function to avoid jest creating a context for all the ramda utilities
Hello @dcalhoun @mdjastrzebski can you please take a look at this? Not sure who are the maintainers of the repo but saw you on other PR. |
Codecov Report
@@ Coverage Diff @@
## main #79 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 8 8
Lines 149 149
Branches 48 50 +2
=========================================
Hits 149 149
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Hm, this is quite unintuitive. Are there other libraries that done similarly to speed up the tests? |
@thymikee Not that i'm aware of, i just was checking why the test on my project are slow(still fixing some other stuff) and found this quick win during the profiling. TBH, it's quite unintuitive if we don't add a comment explaining why it needs to be done. In my opinion is worth to do it as we're gonna improve the experience of the consumers just by modifying some imports but as i'm not the maintainer and won't have to deal with any consequences of this change i understand your POV and respect your decision. In case you wanna give it a try here you got how to profile it https://www.youtube.com/watch?v=RB2g-o39upo from @kentcdodds. The summary is to
after applying the change on our project we went from 425 ms to 121ms. In the CI it meant a reduction of over 30s. |
@thymikee seems like this is
Source: https://ramdajs.com/ |
After consideration I think that despite this is quite counterintuitive I would give it a go. Long term we should probably swap Ramda for something more performance, maybe Rambda or Remeda. But we would have to measure the actual performance of such change. |
🎉 This PR is included in version 4.0.6 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Thanks for checking that @mdjastrzebski |
can't we use babel-transform-imports to transform those imports? |
Sounds like a good idea. @Grohden would you like to prepare a PR for this? |
FYI, this library is last updated 3 years ago, so expect some challenges. |
Yes this looks like related, what is your node version? |
tried with v16.10.0, v12.22.7 and v14.18.1 |
@lokeshdangi That's strange, as I've done checks on my side and it works correctly.
|
I wonder if this relates only to |
@lokeshdangi which version of ramda you have installed? As in your |
@lokeshdangi I've released v4.0.10 which reverses this change. |
@Ne3l I've released v4.0.11 which completely removes Ramda in favor of plain JS. Could you test how that version performs again original Ramda version? |
@mdjastrzebski Thanks for it. Yes it good on my side, here you can see the diff from 4.0.5 to 4.0.11 on the CI of the project i'm working on. |
Import directly the function to avoid jest creating a context for all the ramda utilities
What:
Import directly the ramda functions instead of the global index
Why:
Jest create a virtual machine for every imported file in order to provide a secure context. this has been reported in different jest issues
profiling my project i see that 500ms is spent in everyfile due to the
setupFilesAfterEnv
https://jestjs.io/docs/configuration#setupfilesafterenv-arrayand this is mainly because jest is creating a vm for each ramda function file
This has a tradeoff as it's a bit of incovenience for the mantainers but as this library is very linked to jest, i feel is interesting to pay this small code penalty to provide a faster performance for the consumers.
In my project we have over 200 test files and this change saved more than 30s on the CI testing time.
How:
Modify the import path to point directly to the function file.
Checklist:
docs