Skip to content
This repository has been archived by the owner on Feb 16, 2022. It is now read-only.

switch to using @ebay/nodash/get #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

scttdavs
Copy link

@scttdavs scttdavs commented Mar 12, 2019

uses less js than lodash.get: https://github.com/eBay/nodash

as it is, most teams use lodash anyway, and lodash.get code would not be deduped with it.

Tests passed locally. I'll past the benchmarks below:

Before:

### need() ###

access string
calls:5000, breadth:500, depth:25: 67.402ms
calls:5000, breadth:200, depth:10: 16.013ms
calls:5000, breadth:10, depth:5: 12.143ms

access array
calls:5000, breadth:500, depth:25: 34.681ms
calls:5000, breadth:200, depth:10: 10.799ms
calls:5000, breadth:10, depth:5: 4.468ms

access object
calls:5000, breadth:500, depth:25: 59.724ms
calls:5000, breadth:200, depth:10: 5.469ms
calls:5000, breadth:10, depth:5: 2.558ms

access string with wrong default
calls:5000, breadth:500, depth:25: 20.372ms
calls:5000, breadth:200, depth:10: 16.080ms
calls:5000, breadth:10, depth:5: 13.901ms

access array with wrong default
calls:5000, breadth:500, depth:25: 11.259ms
calls:5000, breadth:200, depth:10: 5.715ms
calls:5000, breadth:10, depth:5: 4.557ms

access object with wrong default
calls:5000, breadth:500, depth:25: 15.940ms
calls:5000, breadth:200, depth:10: 7.566ms
calls:5000, breadth:10, depth:5: 3.082ms

access string with wrong path
calls:5000, breadth:500, depth:25: 49.897ms
calls:5000, breadth:200, depth:10: 24.776ms
calls:5000, breadth:10, depth:5: 6.980ms

access array with wrong path
calls:5000, breadth:500, depth:25: 34.494ms
calls:5000, breadth:200, depth:10: 16.651ms
calls:5000, breadth:10, depth:5: 5.062ms

access object with wrong path
calls:5000, breadth:500, depth:25: 37.700ms
calls:5000, breadth:200, depth:10: 13.226ms
calls:5000, breadth:10, depth:5: 6.531ms


### get() ###

access string
calls:5000, breadth:500, depth:25: 10.605ms
calls:5000, breadth:200, depth:10: 7.605ms
calls:5000, breadth:10, depth:5: 6.473ms

access array
calls:5000, breadth:500, depth:25: 9.058ms
calls:5000, breadth:200, depth:10: 4.696ms
calls:5000, breadth:10, depth:5: 2.308ms

access object
calls:5000, breadth:500, depth:25: 9.965ms
calls:5000, breadth:200, depth:10: 5.841ms
calls:5000, breadth:10, depth:5: 3.020ms

access string with wrong default
calls:5000, breadth:500, depth:25: 9.505ms
calls:5000, breadth:200, depth:10: 7.654ms
calls:5000, breadth:10, depth:5: 2.470ms

access array with wrong default
calls:5000, breadth:500, depth:25: 10.020ms
calls:5000, breadth:200, depth:10: 5.021ms
calls:5000, breadth:10, depth:5: 2.346ms

access object with wrong default
calls:5000, breadth:500, depth:25: 18.204ms
calls:5000, breadth:200, depth:10: 4.357ms
calls:5000, breadth:10, depth:5: 2.801ms

access string with wrong path
calls:5000, breadth:500, depth:25: 10.782ms
calls:5000, breadth:200, depth:10: 14.622ms
calls:5000, breadth:10, depth:5: 5.390ms

access array with wrong path
calls:5000, breadth:500, depth:25: 13.442ms
calls:5000, breadth:200, depth:10: 25.655ms
calls:5000, breadth:10, depth:5: 17.165ms

access object with wrong path
calls:5000, breadth:500, depth:25: 18.419ms
calls:5000, breadth:200, depth:10: 11.130ms
calls:5000, breadth:10, depth:5: 7.458ms

After:

### need() ###

access string
calls:5000, breadth:500, depth:25: 100.777ms
calls:5000, breadth:200, depth:10: 15.046ms
calls:5000, breadth:10, depth:5: 8.411ms

access array
calls:5000, breadth:500, depth:25: 85.163ms
calls:5000, breadth:200, depth:10: 4.060ms
calls:5000, breadth:10, depth:5: 1.952ms

access object
calls:5000, breadth:500, depth:25: 83.898ms
calls:5000, breadth:200, depth:10: 3.992ms
calls:5000, breadth:10, depth:5: 1.985ms

access string with wrong default
calls:5000, breadth:500, depth:25: 18.845ms
calls:5000, breadth:200, depth:10: 11.250ms
calls:5000, breadth:10, depth:5: 7.403ms

access array with wrong default
calls:5000, breadth:500, depth:25: 7.428ms
calls:5000, breadth:200, depth:10: 6.273ms
calls:5000, breadth:10, depth:5: 1.755ms

access object with wrong default
calls:5000, breadth:500, depth:25: 7.853ms
calls:5000, breadth:200, depth:10: 5.841ms
calls:5000, breadth:10, depth:5: 2.536ms

access string with wrong path
calls:5000, breadth:500, depth:25: 94.495ms
calls:5000, breadth:200, depth:10: 18.097ms
calls:5000, breadth:10, depth:5: 6.751ms

access array with wrong path
calls:5000, breadth:500, depth:25: 75.476ms
calls:5000, breadth:200, depth:10: 6.594ms
calls:5000, breadth:10, depth:5: 3.223ms

access object with wrong path
calls:5000, breadth:500, depth:25: 83.661ms
calls:5000, breadth:200, depth:10: 9.132ms
calls:5000, breadth:10, depth:5: 20.586ms


### get() ###

access string
calls:5000, breadth:500, depth:25: 18.714ms
calls:5000, breadth:200, depth:10: 8.357ms
calls:5000, breadth:10, depth:5: 4.166ms

access array
calls:5000, breadth:500, depth:25: 7.348ms
calls:5000, breadth:200, depth:10: 7.639ms
calls:5000, breadth:10, depth:5: 2.499ms

access object
calls:5000, breadth:500, depth:25: 6.477ms
calls:5000, breadth:200, depth:10: 10.187ms
calls:5000, breadth:10, depth:5: 3.166ms

access string with wrong default
calls:5000, breadth:500, depth:25: 7.414ms
calls:5000, breadth:200, depth:10: 5.121ms
calls:5000, breadth:10, depth:5: 2.509ms

access array with wrong default
calls:5000, breadth:500, depth:25: 7.262ms
calls:5000, breadth:200, depth:10: 5.876ms
calls:5000, breadth:10, depth:5: 5.847ms

access object with wrong default
calls:5000, breadth:500, depth:25: 6.582ms
calls:5000, breadth:200, depth:10: 5.084ms
calls:5000, breadth:10, depth:5: 2.777ms

access string with wrong path
calls:5000, breadth:500, depth:25: 8.927ms
calls:5000, breadth:200, depth:10: 9.196ms
calls:5000, breadth:10, depth:5: 3.278ms

access array with wrong path
calls:5000, breadth:500, depth:25: 9.917ms
calls:5000, breadth:200, depth:10: 6.791ms
calls:5000, breadth:10, depth:5: 12.962ms

access object with wrong path
calls:5000, breadth:500, depth:25: 12.675ms
calls:5000, breadth:200, depth:10: 23.096ms
calls:5000, breadth:10, depth:5: 7.054ms

@yomed
Copy link
Contributor

yomed commented Mar 12, 2019

Hey @scttdavs, thanks for the PR. We've had some discussions around removing lodash here, but the primary reason to do so is actually to avoid lodash's internal cache. On apps with heavy usage, the cache ends up being very large and requires frequent garbage collection, thereby significantly increasing CPU usage.

I wonder if nodash caching might have the same issues:
https://github.com/eBay/nodash/blob/7449e927398d0d7c3ec0bb5c0c95bd7a15d01c92/src/getPathArray.js

cc @DylanPiercey

@scttdavs
Copy link
Author

if paths are variable (different depending on user), then it probably would. I could maybe add an option to disable cache or even remove it entirely.. But even large apps should not have that many different paths right? How large was the cache growing to? Was there a comparison done for performance costs to generate the paths every time?

@yomed
Copy link
Contributor

yomed commented Mar 12, 2019

Some time ago there was investigation done by comparing CPU/GC time for the current lodash version vs. an in-house version without caching, and it found GC improvements. Though the fix wasn't prioritized at the time. I do have the code ready from that fix, so I think I'll put up that PR as well, and then we can use mirroring to test both that PR and this one. That should help validate whether it's the cache that is the issue, or maybe something else.

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants