Repository navigation
perf: import ramda functions from per-function modules - #58
Open
MarkusWendorf wants to merge 1 commit into
Open
MarkusWendorf wants to merge 1 commit into
MarkusWendorf wants to merge 1 commit into
Conversation
Root imports from 'ramda' pull the whole library into bundles that don't tree-shake (e.g. Metro by default). Per-function 'ramda/src/*' imports keep only the used functions and are also the smallest with Expo's tree shaking enabled. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collaborator
|
Recently there was an issue proposing the exact opposite: #49 However I need to admit I didn't do a throughout research, I just run one agent to confirm and fix the issue |
Author
|
@5ZYSZ3K haha, that's interesting. I asked the creator of said issue to provide details so we know why tree-shaking was not working for him. |
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I noticed that root imports from
ramdapull the whole library into the bundle. This is not an issue if you have tree-shaking enabled, however by default Expo/Metro based projects do not have tree shaking enabled.EXPO_UNSTABLE_TREE_SHAKING=1can be used to enable it, but is marked as unstable for now.This PR changes to deep imports via
import x from 'ramda/src/xinstead of barrel imports.I setup some tests to see the difference. Not quite sure if
import x from 'ramda/src/xorimport x from 'ramda/es/xis the best way to go.If this is ok to be merged, maybe adding an ESLINT rule for imports would make sense. Let me know.
AI summary ahead ↓
Production app
Expo SDK 58, React Native 0.88, Android, Hermes bytecode.
import { x } from 'ramda'(current)import x from 'ramda/src/x'import { x } from 'ramda'(current)import x from 'ramda/src/x'The Hermes bundle column is the shipped bytecode; ramda's size comes from the minified-JS source map. Tree shaking is Expo's
experimental mode (
EXPO_UNSTABLE_TREE_SHAKING=1+EXPO_UNSTABLE_METRO_OPTIMIZE_GRAPH=1).Example app (already has tree shaking enabled)
apps/benchmarking(Android, minified JS). The app's ownimport { mean } from 'ramda'inBenchmark.jswas replaced with alocal helper so only the library is measured.
import { x } from 'ramda'(current)import x from 'ramda/src/x'import x from 'ramda/es/x'