Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance issue: createRow in tanstack/table-core uses excessive memory #5926

Open
2 tasks done
afreix opened this issue Feb 20, 2025 · 2 comments
Open
2 tasks done

Comments

@afreix
Copy link

afreix commented Feb 20, 2025

TanStack Table version

v8.21.2

Framework/Library version

tanstack/table-core

Describe the bug and the steps to reproduce it

createRow in row.ts (src) allocates new closures for every row in the table. Each table features also allocate closures for each row. These functions could be defined once on a shared prototype.

We've played around with a few solutions, namely using a WeakMap<Table, rowProto> in order to support a shared prototype for all rows in a given table. The WeakMap appears to be necessary given the dynamic application of table features (i.e. we can't share a row prototype across all table instances).

A JS Heap snapshot shows a memory reduction from 141mb --> 11.6mb in examples/vanilla/basic example with this change. Note: there are a few small issues to fix. We expect it to be productionalizable

It's worth reiterating that users pay the cost regardless of whether they interact with the table, since it happens during initialization.

We'd like to collaborate with the maintainers on productionalizing ideas defined in this commit. Thank you!

Your Minimal, Reproducible Example - (Sandbox Highly Recommended)

Reproduction:

  • apply this commit and run the examples/vanilla/basic example
  • compare JS heap dumps before/after

Attached are screenshots of the before/after that we observed locally:

Before
Image

After
Image

Screenshots or Videos (Optional)

An image of tanStack table initialization closures accounting for 59% of retained memory in our application:

Image

Similar issues:

Do you intend to try to help solve this bug with your own PR?

Yes, I think I know how to fix it and will discuss it in the comments of this issue

Terms & Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
@mleibman-db
Copy link

I cleaned up the code a bit and improved how feature mixins are applied so we don't iterate needlessly for each row. See #5927.

@mleibman-db
Copy link

mleibman-db commented Feb 25, 2025

This problem can also be easily demonstrated using the grouping demo from the docs - https://tanstack.com/table/v8/docs/framework/react/examples/grouping. Just rendering the table takes up 293 Mb (just the preview IFrame). Grouping by first name jumps it up to 1.5 Gb, and grouping by last name also raises it to 2.5 Gb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants