Speeding up JavaScript Arrays with Transducers. RxJS vs Ramda vs Lodash

Описание к видео Speeding up JavaScript Arrays with Transducers. RxJS vs Ramda vs Lodash

Transducers are a fairly unknown trend in functional programming that provides a significant boost to array performance in JavaScript.

This talk was originally done at KCDC 2021.

The most important thing about transducers has to do with their ability to do multiple transformations on each item in a pipeline prior to outputting those results.

Most functional pipelines do a single action across a number of items for each step in the pipeline. Transducers do all this work once for each item and then choose when or how to set those back into a collection if at all.

While they're not widely known, I provide benchmarks displaying their performance and even go over the implementation I wrote for the presentation itself.

We review various transducer libraries including JavaScript built-in Array.prototype methods, RxJS, Ramda, Thi.ng, Lodash, and others.

My first look at transducers came from Eric Elliot:    / @_ericelliott  

0:00 Speeding up JavaScript Arrays with transducers
0:59 Overview 1. Loops (yes, really...). 2. Array methods.
1:19 Let's start with a for loop.
1:30 Increment the index.
2:16 stop computing length each loop.
2:28 Why are we looping?
3:23 map returns a new array
4:03 implicit return
4:16 common Array.prototype methods
4:58 and functional programming
6:14 composition
7:37 reduce has state
8:21 reduce is a 'ducer
8:25 WHY Array.prototype?
8:30 easier to perform multiple operations on an array
8:40 removes boilerplate
8:47 Array.prototype issues
8:51 constantly creating new arrays
9:06 Array.prototype alternatives
11:27 synchronous
12:20 standard functional programming
12:40 What's a transducer?
13:28 I learned about transducers from Eric Elliott
13:50 that's a trans-ducer
13:53 it transforms a reducer into another reducer
14:01 Why use transducers?
14:19 iterate loop all items
15:16 examples
16:39 transducers work backward
17:50 easier to use
19:01 transform run all transformations
20:35 let's write transducers
22:09 index is a counter
22:16 counters requires state
23:24 don't worry about it
25:35 let's write map
25:47 calling map transducer
27:03 let's write filter
31:40 reduce stores an array of values
31:43 reduce waits for all values
34:26 transducers are hard
34:55 incrementing transform
37:18 duplicate up
40:01 stats
41:40 Ramda transducers don't run at scale
45:01 Array.prototype is fast
49:16 i have a story
50:39 bad JS leads to bad performance
51:40 only when looping 5K items
52:01 functional code is readable
52:04 maintenance performance

Комментарии

Информация по комментариям в разработке