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

Memoizes the functions for getting header both runs and scalar data tables #6836

Merged
merged 3 commits into from
Apr 24, 2024

Conversation

hoonji
Copy link
Member

@hoonji hoonji commented Apr 22, 2024

Motivation for features / changes

Using functions in Angular templates leads to unnecessary recomputation, e.g. getHeaders() is called 60 times from data tables on init and add). More seriously, they also interfere with other component usage like CDK Overlay: namely, when an Overlay is set to appear next to a header, the header element is destroyed and recreated (because of the function in the template) before the Overlay can position itself, and ends up always resetting its position to (0,0). Simply memoizing the function will prevent the recomputation (Angular ref).

Profiling the memoized change (using Chrome devtools profiler, which is admittedly a bit inconsistent) seems to show a several 100ms improvement in scripting performance.

Technical description of changes

Replaces the getHeaders functions used in scalar/runs data tables with a new memoized extendHeaders(headers) function.

No change in UI behavior.

Screenshots of UI changes (or N/A)

N/A

extendHeaders = memoize(this.internalExtendHeaders);

private internalExtendHeaders(headers: ColumnHeader[]) {
return ([] as Array<ColumnHeader>).concat(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, any idea why we are using concat instead of the spread operator?

return [
        {
          name: 'color',
          displayName: '',
          type: ColumnHeaderType.COLOR,
          enabled: true,
        },
        ...headers
      ],
    );

Is it also for performance?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concat is more performant.

@hoonji hoonji merged commit 9f51a30 into master Apr 24, 2024
16 checks passed
@hoonji hoonji deleted the memoize_column_fn branch April 24, 2024 11:19
AnuarTB pushed a commit to AnuarTB/tensorboard that referenced this pull request May 3, 2024
…ables (tensorflow#6836)

## Motivation for features / changes
Using functions in Angular templates leads to unnecessary recomputation,
e.g. getHeaders() is called 60 times from data tables on init and add).
More seriously, they also interfere with other component usage like CDK
Overlay: namely, when an Overlay is set to appear next to a header, the
header element is destroyed and recreated (because of the function in
the template) before the Overlay can position itself, and ends up always
resetting its position to (0,0). Simply memoizing the function will
prevent the recomputation ([Angular
ref](https://angular.io/guide/change-detection-slow-computations#optimizing-slow-computations)).

Profiling the memoized change (using Chrome devtools profiler, which is
admittedly a bit inconsistent) seems to show a several 100ms improvement
in scripting performance.

## Technical description of changes
Replaces the `getHeaders` functions used in scalar/runs data tables with
a new memoized `extendHeaders(headers)` function.

No change in UI behavior.

## Screenshots of UI changes (or N/A)
N/A
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

3 participants