Skip to content

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

Open
@afreix

Description

@afreix

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions