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

Conversation

@yomed
Copy link
Contributor

@yomed yomed commented Mar 14, 2019

Description

  • implement version of lodash.get internally, and importantly, without caching
  • remove lodash.get dependency
  • minor refactoring and renaming

Context

@DylanPiercey did some initial investigation around lodash.gets cache actually doing more harm than good for certain cases. It seemed that the cache required additional garbage collection time, which increased CPU usage across the board. In this PR, I've taken his initial code and made a few adjustments.

We will need to rerun the GC/CPU analysis. I'm putting the code here so it's easier to do that. We now also have #12, which we could potentially use for comparison.

Perf data:

Before:

### need() ###

access string
calls:5000, breadth:500, depth:25: 49.728ms
calls:5000, breadth:200, depth:10: 22.277ms
calls:5000, breadth:10, depth:5: 10.672ms

access array
calls:5000, breadth:500, depth:25: 36.228ms
calls:5000, breadth:200, depth:10: 5.139ms
calls:5000, breadth:10, depth:5: 2.562ms

access object
calls:5000, breadth:500, depth:25: 51.407ms
calls:5000, breadth:200, depth:10: 5.761ms
calls:5000, breadth:10, depth:5: 2.663ms

access string with wrong default
calls:5000, breadth:500, depth:25: 15.403ms
calls:5000, breadth:200, depth:10: 19.166ms
calls:5000, breadth:10, depth:5: 2.773ms

access array with wrong default
calls:5000, breadth:500, depth:25: 10.729ms
calls:5000, breadth:200, depth:10: 5.314ms
calls:5000, breadth:10, depth:5: 2.895ms

access object with wrong default
calls:5000, breadth:500, depth:25: 10.965ms
calls:5000, breadth:200, depth:10: 6.855ms
calls:5000, breadth:10, depth:5: 2.614ms

access string with wrong path
calls:5000, breadth:500, depth:25: 46.318ms
calls:5000, breadth:200, depth:10: 19.278ms
calls:5000, breadth:10, depth:5: 16.806ms

access array with wrong path
calls:5000, breadth:500, depth:25: 40.307ms
calls:5000, breadth:200, depth:10: 11.825ms
calls:5000, breadth:10, depth:5: 5.820ms

access object with wrong path
calls:5000, breadth:500, depth:25: 38.945ms
calls:5000, breadth:200, depth:10: 12.961ms
calls:5000, breadth:10, depth:5: 6.498ms


### get() ###

access string
calls:5000, breadth:500, depth:25: 11.766ms
calls:5000, breadth:200, depth:10: 8.993ms
calls:5000, breadth:10, depth:5: 2.671ms

access array
calls:5000, breadth:500, depth:25: 10.150ms
calls:5000, breadth:200, depth:10: 5.865ms
calls:5000, breadth:10, depth:5: 2.592ms

access object
calls:5000, breadth:500, depth:25: 11.270ms
calls:5000, breadth:200, depth:10: 6.605ms
calls:5000, breadth:10, depth:5: 4.495ms

access string with wrong default
calls:5000, breadth:500, depth:25: 11.732ms
calls:5000, breadth:200, depth:10: 8.324ms
calls:5000, breadth:10, depth:5: 2.746ms

access array with wrong default
calls:5000, breadth:500, depth:25: 10.266ms
calls:5000, breadth:200, depth:10: 5.784ms
calls:5000, breadth:10, depth:5: 2.619ms

access object with wrong default
calls:5000, breadth:500, depth:25: 11.900ms
calls:5000, breadth:200, depth:10: 5.964ms
calls:5000, breadth:10, depth:5: 2.667ms

access string with wrong path
calls:5000, breadth:500, depth:25: 12.989ms
calls:5000, breadth:200, depth:10: 11.507ms
calls:5000, breadth:10, depth:5: 6.339ms

access array with wrong path
calls:5000, breadth:500, depth:25: 13.481ms
calls:5000, breadth:200, depth:10: 12.912ms
calls:5000, breadth:10, depth:5: 5.984ms

access object with wrong path
calls:5000, breadth:500, depth:25: 13.769ms
calls:5000, breadth:200, depth:10: 12.975ms
calls:5000, breadth:10, depth:5: 6.064ms

After:

### need() ###

access string
calls:5000, breadth:500, depth:25: 19.270ms
calls:5000, breadth:200, depth:10: 15.027ms
calls:5000, breadth:10, depth:5: 7.294ms

access array
calls:5000, breadth:500, depth:25: 13.328ms
calls:5000, breadth:200, depth:10: 8.136ms
calls:5000, breadth:10, depth:5: 3.124ms

access object
calls:5000, breadth:500, depth:25: 10.418ms
calls:5000, breadth:200, depth:10: 5.380ms
calls:5000, breadth:10, depth:5: 3.131ms

access string with wrong default
calls:5000, breadth:500, depth:25: 15.182ms
calls:5000, breadth:200, depth:10: 10.502ms
calls:5000, breadth:10, depth:5: 7.763ms

access array with wrong default
calls:5000, breadth:500, depth:25: 12.230ms
calls:5000, breadth:200, depth:10: 5.270ms
calls:5000, breadth:10, depth:5: 3.126ms

access object with wrong default
calls:5000, breadth:500, depth:25: 13.192ms
calls:5000, breadth:200, depth:10: 6.321ms
calls:5000, breadth:10, depth:5: 3.789ms

access string with wrong path
calls:5000, breadth:500, depth:25: 15.563ms
calls:5000, breadth:200, depth:10: 18.917ms
calls:5000, breadth:10, depth:5: 5.856ms

access array with wrong path
calls:5000, breadth:500, depth:25: 10.714ms
calls:5000, breadth:200, depth:10: 8.062ms
calls:5000, breadth:10, depth:5: 3.774ms

access object with wrong path
calls:5000, breadth:500, depth:25: 10.419ms
calls:5000, breadth:200, depth:10: 8.403ms
calls:5000, breadth:10, depth:5: 3.799ms


### get() ###

access string
calls:5000, breadth:500, depth:25: 18.463ms
calls:5000, breadth:200, depth:10: 9.778ms
calls:5000, breadth:10, depth:5: 5.995ms

access array
calls:5000, breadth:500, depth:25: 10.492ms
calls:5000, breadth:200, depth:10: 5.830ms
calls:5000, breadth:10, depth:5: 3.462ms

access object
calls:5000, breadth:500, depth:25: 13.495ms
calls:5000, breadth:200, depth:10: 7.194ms
calls:5000, breadth:10, depth:5: 4.009ms

access string with wrong default
calls:5000, breadth:500, depth:25: 10.832ms
calls:5000, breadth:200, depth:10: 7.971ms
calls:5000, breadth:10, depth:5: 3.786ms

access array with wrong default
calls:5000, breadth:500, depth:25: 14.533ms
calls:5000, breadth:200, depth:10: 8.137ms
calls:5000, breadth:10, depth:5: 4.087ms

access object with wrong default
calls:5000, breadth:500, depth:25: 19.196ms
calls:5000, breadth:200, depth:10: 8.625ms
calls:5000, breadth:10, depth:5: 4.863ms

access string with wrong path
calls:5000, breadth:500, depth:25: 15.079ms
calls:5000, breadth:200, depth:10: 8.646ms
calls:5000, breadth:10, depth:5: 5.844ms

access array with wrong path
calls:5000, breadth:500, depth:25: 16.023ms
calls:5000, breadth:200, depth:10: 7.213ms
calls:5000, breadth:10, depth:5: 4.360ms

access object with wrong path
calls:5000, breadth:500, depth:25: 12.368ms
calls:5000, breadth:200, depth:10: 7.572ms
calls:5000, breadth:10, depth:5: 4.590ms

Copy link
Contributor

@sidsakhadeo sidsakhadeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants