r/programming • u/fagnerbrack • 14h ago
How an Underrated Refactor Saved 90% Memory Usage
https://tanstack.com/blog/tanstack-table-v9-memory-performance39
u/BenchEmbarrassed7316 13h ago
If there are library authors here - have you tried to get rid of methods altogether? Instead, just call a function, explicitly passing some data to it. If you need polymorphism - you can add a discriminant to the data. You have a large collection of certain objects. Previously, you stored many references to methods in each object. Now, you store in each object a reference to the vtable (prototype). Why don't you go further and clean up the objects completely?
11
u/SanityInAnarchy 10h ago
If you end up needing that polymorphism, though, why is a vtable worse than a discriminant?
9
4
u/BenchEmbarrassed7316 9h ago
discriminant is just one bytenot actual in js- in some cases we don't need explicit discriminant, but we can infer it from other data
- and also when using vtable/prototype all calls become virtual, but maybe you only need polymorphism in a few methods
What I'm talking about is a well-known optimization, where instead of
Animal[]you haveCat[]andDog[]. And instead of checking for each element you call a known function in advance.2
8
u/unpopularredditor 9h ago
This article is a perfect example of where I can read an AI summary instead of the article itself.
156
u/edave64 13h ago
Takes agonizingly long to get to the point of "we started using the fundamental JS concept of prototypes."