DEV Community

Discussion on: Understand Memoization in 5 Minutes

Collapse
faiwer profile image
Stepan Zubashev

Plz avoid using JSON.stringify for memoization keys.

  • It doesn't support anything except json-likes things
  • it's extremely slow

But you can use:

  • Maps for objects keys
  • WeakMaps for objects avoiding GC
  • Custom non-object keys
Collapse
nas5w profile image
Nick Scialli (he/him) Author

I appreciate the note.

I did already call out that JSON.stringify is suboptimal in the article.

Collapse
jbnv profile image
Jay Bienvenu

Yet after you did that, you never gave an optimal alternative. You said it was "suboptimal" yet repeated it in your "optimal" solution.