diff --git a/README.md b/README.md index cfdcba84..9c907cd9 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/assets/images/ydnlu.png b/assets/images/ydnlu.png new file mode 100644 index 00000000..52bb864e Binary files /dev/null and b/assets/images/ydnlu.png differ diff --git a/sections/performance/nativeoverutil.md b/sections/performance/nativeoverutil.md index 2748daeb..5f3da7a8 100644 --- a/sections/performance/nativeoverutil.md +++ b/sections/performance/nativeoverutil.md @@ -1,10 +1,20 @@ # Prefer native JS methods over user-land utils like Lodash +

### 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` + - ... + @@ -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.