So, after about 1 month of
#omnixent public beta, here&
#39;s what I learned about making
#Nodejs really, really fast and leaving a low footprint on your server.
A thread

https://abs.twimg.com/emoji/v2/... draggable="false" alt="👇" title="Rückhand Zeigefinger nach unten" aria-label="Emoji: Rückhand Zeigefinger nach unten">

https://abs.twimg.com/emoji/v2/... draggable="false" alt="1️⃣" title="Tastenkappe Ziffer 1" aria-label="Emoji: Tastenkappe Ziffer 1"> Stop thinking of
#JavaScript as an imperative language. Approaching it as a functional language (adopting methods such as map/reduce) makes it really, really fast and safe. Even when working on objects, I do prefer the FP approach (Object.keys(obj).reduce(...)).

https://abs.twimg.com/emoji/v2/... draggable="false" alt="2️⃣" title="Tastenkappe Ziffer 2" aria-label="Emoji: Tastenkappe Ziffer 2"> Make it lazy. Strict evaluation might be faster, but once your arrays and objects start to get a huge number of entries/properties, iterating over them will slow down the process by a lot. Use Set/Map OR hashmap + lazy properties. You will be computing values when you need

https://abs.twimg.com/emoji/v2/... draggable="false" alt="3️⃣" title="Tastenkappe Ziffer 3" aria-label="Emoji: Tastenkappe Ziffer 3"> Make it deterministic. Using pure functions will allow you to memoize expensive function calls and computations

https://abs.twimg.com/emoji/v2/... draggable="false" alt="4️⃣" title="Tastenkappe Ziffer 4" aria-label="Emoji: Tastenkappe Ziffer 4"> Avoid external libraries.
#Lodash,
#Ramda, etc., are awesome, but with
#ESNext, you can probably solve your problems without the need for _.get and other methods.

https://abs.twimg.com/emoji/v2/... draggable="false" alt="5️⃣" title="Tastenkappe Ziffer 5" aria-label="Emoji: Tastenkappe Ziffer 5"> Use
#TypeScript. It&
#39;s a pain, and we all agree on that, but type safety is something you don&
#39;t want to negotiate with.

https://abs.twimg.com/emoji/v2/... draggable="false" alt="6️⃣" title="Tastenkappe Ziffer 6" aria-label="Emoji: Tastenkappe Ziffer 6"> Think parallel. Pure functions allow you to parallelize your code with ease by using worker threads, promises, clustering, etc.

https://abs.twimg.com/emoji/v2/... draggable="false" alt="7️⃣" title="Tastenkappe Ziffer 7" aria-label="Emoji: Tastenkappe Ziffer 7"> Try to understand how the event loop works. Don&
#39;t be afraid to use process.nextTick if you really need to, just avoid use timeouts to free the stack before allocating a new call

https://abs.twimg.com/emoji/v2/... draggable="false" alt="8️⃣" title="Tastenkappe Ziffer 8" aria-label="Emoji: Tastenkappe Ziffer 8"> Let your functions accept one argument only. If you really need to pass multiple values, use currying or pass a statically typed object with TypeScript. It will be easier for you to think about your function.

https://abs.twimg.com/emoji/v2/... draggable="false" alt="9️⃣" title="Tastenkappe Ziffer 9" aria-label="Emoji: Tastenkappe Ziffer 9"> Shit happens. If you cannot connect to
#Redis or any other external data source, make sure that any call to that source results in a no-op.

https://abs.twimg.com/emoji/v2/... draggable="false" alt="1️⃣" title="Tastenkappe Ziffer 1" aria-label="Emoji: Tastenkappe Ziffer 1">

https://abs.twimg.com/emoji/v2/... draggable="false" alt="0️⃣" title="Tastenkappe Ziffer 0" aria-label="Emoji: Tastenkappe Ziffer 0"> Shit happens pt.2. Wrap your uncertain call into an async function. Always test for failure when spawning your functions. They will fail on a separate process leaving the main thread free from exceptions
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.