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

enhance: update path to use prop function #3428

Closed
wants to merge 2 commits into from

Conversation

ridge-kimani
Copy link
Contributor

@ridge-kimani ridge-kimani commented Nov 17, 2023

Description

  • updates the R.path to reuse the prop function.

Type of change

  • chore(non-breaking change which adds functionality)

Closes #3429

How Has This Been Tested?

  • Run npm test and npm run browser_test

@ridge-kimani ridge-kimani changed the title chore: update path to use prop function enhancement: update path to use prop function Nov 17, 2023
@ridge-kimani ridge-kimani changed the title enhancement: update path to use prop function enhance: update path to use prop function Nov 17, 2023
@kedashoe
Copy link
Contributor

ty for the PR @ridge-kimani , however I don't see the need to refactor here unless you can prove this version is faster which it seems to me it would not be.

@ridge-kimani
Copy link
Contributor Author

@kedashoe there are some significant improvements in performance. For the test cases, the highest runtime was at 1.6s compared to 1.4s for this case. The obj null check also comes before the loop.

@kedashoe
Copy link
Contributor

Running tests isn't meant to be used as a benchmark, too much noise. I built a quick benchmark and the current impl is significantly faster

│ this-pr                │ 3,186,532              │ 0.53%                  │
├────────────────────────┼────────────────────────┼────────────────────────┤
│ current                │ 5,016,350              │ 0.19%                  │

@kedashoe kedashoe closed this Nov 23, 2023
@Berndy
Copy link
Contributor

Berndy commented Dec 4, 2023

I'm a bit late to the party, but I have thought about this as well... I think it makes sense to only have a single definition how we get properties from an object, the same way we use nth everywhere to get a value form an array/string or path to get a nested value.

The performance hit here almost certainly comes from calling a curried version of R.prop. We'd have to move an uncurried version to an internal file and replace the usage of the curried version everywhere, similar to how nth and path were refactored in my earlier PR. This would result in some performance gain for all prop related functions, with this refactor being a nice side effect.

Also the null check needs to stay in the for loop as we want to escape as soon as we hit any null-ish value.

@kedashoe
Copy link
Contributor

kedashoe commented Dec 4, 2023

I think it makes sense to only have a single definition how we get properties from an object, the same way we use nth everywhere to get a value form an array/string or path to get a nested value.

For me the reason using/optimizing nth makes sense is that it is doing more stuff (checking for negative indexes, checking if target object is a string). Having a single definition for getting properties might be nice, but as ramda is a library, it is more important for me what our users experience than what we experience writing the library, ie performance is more important than that our code is nice.

Can we really make _path faster by replacing a plain js val = val[p]; with a call to an internal _prop function?

Having said that, a PR for an internal _prop function that does not use currying to replace our current calls to prop would make sense to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

enhancement: update path to use prop
3 participants