Skip to content

Commit

Permalink
Updated README and a section
Browse files Browse the repository at this point in the history
  • Loading branch information
Berkmann18 committed Jan 1, 2019
1 parent 98a6ae1 commit ecb875c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -958,8 +958,9 @@ All statements above will return false if used with `===`
## ![] 7.1. Prefer native JS methods over user-land utils like Lodash

**TL;DR:** It's often more penalising to use utility libraries like `lodash` and `underscore` over native methods as it leads to unneeded dependencies and slower performance.
Bar in mind that with the introduction of the new V8 engine alongside the new ES standards, native methods were improved in such a way that it's now about 50% more performant than utility libraries.

**Otherwise:** You'll have to maintain (slightly) bigger projects where you could have simply used what was **already** available or dealt with a few more lines in exchange of a few more files.
**Otherwise:** You'll have to maintain less performant projects where you could have simply used what was **already** available or dealt with a few more lines in exchange of a few more files.

🔗 [**Read More: Native over user land utils**](/sections/performance/nativeoverutil.md)

Expand Down
Binary file added assets/images/ydnlu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 13 additions & 8 deletions sections/performance/nativeoverutil.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
# Prefer native JS methods over user-land utils like Lodash


<br/><br/>

### One Paragraph Explainer

Sometimes, using native methods is better than requiring `lodash` or `underscore` because the resulting program will have more dependencies and thus use more space and also not guarantee the best performance all-round.
Sometimes, using native methods is better than requiring `lodash` or `underscore` because it **will not lead in a performance boost** and use more space than necessary.
The performance using native methods result in an overall ~50% gain which includes the following methods:
- `Array.concat`
- `Array.fill`
- `Array.filter`
- `Array.map`
- `(Array|String).indexOf`
- `Object.find`
- ...


<!-- comp here: https://gist.github.com/Berkmann18/3a99f308d58535ab0719ac8fc3c3b8bb-->

Expand Down Expand Up @@ -78,13 +88,8 @@ if (_.includes(arr, 0)) console.log('0 found');
console.log('compacted:', _.compact(arr));
```

### Example: detecting non-v8 util usage using a linter
Here's what ESLint would output when using the YDNLU plugin.
```bash
/home/maxie/GDrive/Other/Sandbox/YDNLU/lodashLove.js
5:13 warning Consider using the native Array.prototype.map() you-dont-need-lodash-underscore/map
7:5 warning Consider using the native Array.prototype.includes() you-dont-need-lodash-underscore/includes

✖ 2 problems (0 errors, 2 warnings)
```
![output](../../assets/images/ydnlu.png)

Of course, the example above doesn't seem realistic considering what actual codebases would have but you get the idea.

0 comments on commit ecb875c

Please sign in to comment.