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

Reduce re-derivation of body rows and columns #4

Merged
merged 10 commits into from
May 12, 2022

Conversation

bryanmylee
Copy link
Owner

The original strategy had plugins expose a row transformation function in a Readable, to which useTable then subscribed to transform originalRows into the final set of rows to display.

const rows = derived([originalRows, ...transforms], ...);

However, this meant that any updates to plugin state would cause the entire derivation to recompute from originalRows to rows.

We can improve plugin performance – especially if plugin state being updated is at the end of the transformations – by creating a chain of derived stores.

The goal is to only recompute rows from the point of a plugin that updated and onwards.

originalRows
  .map(sort)      <- do not update this
  .map(filter)    <- plugin state changes
  .map(paginate)  <- only update this

To do so, each plugin receives a Readable<BodyRow[]> store which it uses to derive a transformed Readable<BodyRow[]> store. Plugins can then be chained together by passing the result of one plugin to the next. By creating this chain, the only dependencies of a plugin's derived rows are its own plugin state and the previous plugin's derived rows, minimizing the re-computation required.

const useSortBy = () => {
  ...
  return {
    deriveRows: (rows: Readable<BodyRow[]>) => derived([rows, state], ...),
  }
}

const useTable = () => {
  ...
  let rows = originalRows;
  deriveRowsFns.forEach(fn => {
    rows = fn(rows);
  });
  ...
}

@bryanmylee bryanmylee merged commit f3ec56d into main May 12, 2022
@coveralls
Copy link

coveralls commented May 12, 2022

Pull Request Test Coverage Report for Build 2315042871

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 81.529%

Totals Coverage Status
Change from base Build 2311762508: 0.0%
Covered Lines: 217
Relevant Lines: 260

💛 - Coveralls

@bryanmylee bryanmylee deleted the perf/row-transformations branch May 16, 2022 16:19
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

Successfully merging this pull request may close these issues.

None yet

2 participants