Alagarasan Profile picture
Jan 27 9 tweets 10 min read
Memoization: Using Proxy in JavaScript

#100DaysOfCode #javascript #rarely_used #devbubble
Memoization is a technique used to optimize the performance of a function by caching its results for a given set of inputs.

#100DaysOfCode #reactjs #Angular #NodeJS
The idea is that if a function is called multiple times with the same input, it's more efficient to return the cached result instead of re-computing the result each time.

#100daysofcodingchallenge #reactjs #Angular #NodeJS
In this example, we use the apply trap to intercept the call to the fibonacci function.

We use the first argument of the function call as a key to check if a cached result is available in the cache map.

#100DaysOfCode #javascript #Angular #NodeJS #reactjs #devbubble Memoization using Proxy in JS
If it is, we return the cached result. If it isn't, we call the original function using the Reflect.apply method, and store the result in the cache.

#100DaysOfCode #javascript #Angular #NodeJS #reactjs #devbubble Invoking a Proxy-memoized function in JS
This approach can be useful for situations where you have a function that is called multiple times with the same inputs, and the function's result is relatively expensive to compute.

#coding #reactjs #NodeJS #Angular
By using a Proxy to implement memoization, we can ensure that the function's result is only computed once for a given set of inputs, & any subsequent calls with the same inputs will return the cached result, leading to a performance boost.

#javascript30 #reactjs #NodeJS #Angular
You may have had doubts like can I not use the Map directly instead of a Proxy?

Yes, you can, but the Proxy provides traps for better control. I'll post a new thread for that. This is just a sample for your understanding.

#100DaysOfCode #javascript #reactjs #Angular #devbubble
Let me know in the comments if you have any questions.

If you enjoyed this thread, kindly RT🔁 the first tweet.

This account exists to help you:
- Learn & revamp your web-dev skills

Follow🏃 @AlagarasanWDev ... let's learn together.

That's a wrap!
❤️
Cheers!

#techtwitter

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Alagarasan

Alagarasan Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @AlagarasanWDev

Jan 28
Generator function* in JavaScript:

A thread 🧵

#100DaysOfCode #javascript #Angular #reactjs #devbubble
In JavaScript, generator functions are a special type of function that allows you to use the yield keyword to pause and resume the execution of the function.

#100DaysOfCode #NodeJS #CodeLife
They allow you to create iterators, which are objects that can be used to iterate over a sequence of values.

A generator function is defined using the function* keyword and can be invoked using the yield keyword.

#100daysofcodechallenge #NodeJS #reactjs
Read 8 tweets
Jan 26
Data virtualization: With Proxies in JavaScript.

A thread 🧵

#100DaysOfCode #javascript #rarely_used #devbubble
Data virtualization using Proxies in JavaScript refers to the ability to create virtualized data structures, such as virtualized arrays, that load their data on demand rather than loading all data at once.

#100DaysOfCode #ReactJS #Angular
This can be useful for improving the performance of an application when working with large data sets.

In this Eg., we create a VirtualArray class that takes in two args- the length of the array & a loader function.

#100DaysOfCode #javascript #NodeJS #ReactJs #Angular #devbubble Proxy - VirtualArray in JS
Read 8 tweets
Jan 18
WeakMap in JavaScript

A thread 🧵

#100DaysOfCode #javascript #rarely_used
A WeakMap is a map that holds weak references to its keys.

This means that the keys are eligible for garbage collection if there are no other references to them.

This feature can be useful for implementing caches or other similar data structures.

#reactjs #Angular #NodeJS #js
A WeakMap is a special kind of map where keys must be objects and the map doesn't prevent garbage collection of its keys.

You can think of a WeakMap as a map that doesn't "own" its keys, and therefore doesn't keep them alive.

#100daysofcodechallenge #100DaysOfCode
Read 9 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(