memotable - A tiny JS library for finely-reactive, derived collections #2561
shudv
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
_Disclaimer: I am not a SolidJS expert. I am posting this here because based on my limited understanding - I feel SolidJS community would care about the "long tail" of performance issues much more as compared to other frameworks.
Problem
While working with React apps, one common pitfall I notice overuse of hooks. As an example, the hook
useMemois almost always misused. If you use it to memoize simple O(1) computations, the performance improvement won't make a difference in any realistic scenario (unless the O(1) computation is super heavy which is rare). If you use it to memoize collections and their derivatives (e.g. filtered and sorted views), it does not actually work-This is deceptive as it looks correct but it isn't-
Proposed solution
I built a tiny library — memotable (≈1.4 KB min+gz and ≈1.0 KB min+br). It’s a read-friendly data structure which can maintain derived views efficiently. This matters only for a narrow set of apps (typically apps that manage large in-memory datasets).
Instead of the typical write-friendly pattern-
you can express the same as a read-friendly structure using memotable's
Tableprimitive-Reads are effectively free because the view is already materialized. Writes cost more, but for read-heavy workloads it's a good trade-off. As an example- based on my synthetic benchmark with R/W ratio of 4:1, memotable turns out to be ~4x faster.
I am curious if anyone here has explored this before and found a simpler alternative. Please share your feeback/inputs-
Repo: https://github.com/shudv/memotable
Beta Was this translation helpful? Give feedback.
All reactions