Skip to content

Make preview selections faster by only dispatching on changes#1481

Merged
gregtatum merged 1 commit intofirefox-devtools:masterfrom
gregtatum:limit-preview-selection-dispatches
Nov 12, 2018
Merged

Make preview selections faster by only dispatching on changes#1481
gregtatum merged 1 commit intofirefox-devtools:masterfrom
gregtatum:limit-preview-selection-dispatches

Conversation

@gregtatum
Copy link
Member

I was running into performance issues on the JS Tracer chart when dispatching many equivalent preview selections. This happens especially when scrolling out to the maximum zoom level. I did not include a test specifically for this behavior change, but we have existing coverage over the action, so to me it didn't seem worth it. I will double check the coverage information once it comes back from CI.

@gregtatum gregtatum requested a review from canova November 9, 2018 19:50
/**
* Perform a simple shallow object equality check.
*/
export function objectShallowEquals(a: Object, b: Object): boolean {
Copy link
Member Author

Choose a reason for hiding this comment

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

I felt that it was simpler to write this function than to include an additional dependency the project. I think we previously had some lodash functions, but now I'm not seeing any, so I didn't want to add additional bytes to the bundle for something so small.

Copy link
Member

Choose a reason for hiding this comment

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

Seems reasonable to me.

@codecov
Copy link

codecov bot commented Nov 9, 2018

Codecov Report

Merging #1481 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1481      +/-   ##
==========================================
+ Coverage   80.79%   80.81%   +0.02%     
==========================================
  Files         157      157              
  Lines       10792    10807      +15     
  Branches     2627     2631       +4     
==========================================
+ Hits         8719     8734      +15     
  Misses       1874     1874              
  Partials      199      199
Impacted Files Coverage Δ
src/utils/index.js 100% <100%> (ø) ⬆️
src/actions/profile-view.js 90.24% <100%> (+0.1%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d980425...1c73bb2. Read the comment docs.

gregtatum added a commit to gregtatum/perf.html that referenced this pull request Nov 9, 2018
Copy link
Member

@canova canova left a comment

Choose a reason for hiding this comment

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

Looks good to me. But since we are now doing more calculations for every preview selection change, I'm not sure if that really makes it faster. Do you have an example of mentioned performance problem?

I also have an optional suggestion for the objectShallowEquals but not super sure about it. It's your call :)

/**
* Perform a simple shallow object equality check.
*/
export function objectShallowEquals(a: Object, b: Object): boolean {
Copy link
Member

Choose a reason for hiding this comment

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

Seems reasonable to me.

@gregtatum
Copy link
Member Author

Looks good to me. But since we are now doing more calculations for every preview selection change, I'm not sure if that really makes it faster. Do you have an example of mentioned performance problem?

I didn't keep the profiles I was recording, but it was with an earlier version of the JS tracer chart. It would make my browser barely function when I was zooming out, but the viewport wasn't actually changing.

As for the extra calculations, these objects have only a few properties, so in practice the equality check should be almost free. Any dispatch to the Redux store has a non-trivial cost associated with it. Unfortunately, objects of the same shape, still trigger re-renders, since they fail the equality test. So this should reduce the number of dispatches that we perform overall, with little cost to the normal functioning.

@gregtatum gregtatum force-pushed the limit-preview-selection-dispatches branch from c4c6b79 to 1c73bb2 Compare November 12, 2018 16:19
@gregtatum gregtatum merged commit 7866604 into firefox-devtools:master Nov 12, 2018
gregtatum added a commit to gregtatum/perf.html that referenced this pull request Aug 12, 2025
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.

2 participants