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

less dom reads #358

Merged
merged 12 commits into from
Mar 5, 2018
Merged

less dom reads #358

merged 12 commits into from
Mar 5, 2018

Conversation

alexreardon
Copy link
Collaborator

Closes #329.

Fixing a minor performance regressed in lifting big data sets with our new auto scroller.

What this PR does:

  • avoids independent calls to functions that request values from the window from the state folder (engineering health)
  • Fixes minor perf regression on lift. This was caused by reading window properties at bad times in an animation frame. There were a few ways around it. But this method gets around the problem while also doing something we wanted to anyway.

The code changes in src are super basic. There was some more heavy lifting required to get everything working in the tests. Previously tests were setting viewport properties in anticipation of the viewport being read. Now these properties can be passed directly to functions

// window.innerWidth / innerHeight includes scrollbar
// however the scrollHeight / scrollWidth do not :(

const maxScroll: Position = getMaxScroll({
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is now computed in getViewport

@@ -0,0 +1,46 @@
// @flow
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

another debug middleware - this one averages the time taken for actions and prints a result

@@ -49,8 +51,6 @@ export default ({
sourceClipped[axis.start],
sourceClipped[axis.end]
);
const viewport: Area = getViewport();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

that's what i'm talking about 👍

@@ -74,7 +73,6 @@ export default ({
return 'start';
})();

const viewport: Area = getViewport();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

goodbye old friend

const drag: ?DragState = state.drag;

if (!drag) {
console.error('cannot move with window scrolling if no current drag');
return clean();
}

if (isEqual(windowScroll, drag.current.windowScroll)) {
// TODO: need to improve this so that it compares the whole viewport
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this check is good enough for now

@@ -13,7 +13,7 @@ import type {
import DraggableDimensionPublisher from '../draggable-dimension-publisher/';
import Moveable from '../moveable/';
import DragHandle from '../drag-handle';
import getWindowScroll from '../../window/get-window-scroll';
import getViewport from '../window/get-viewport';
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is now the only thing that publishes the viewport into the state

});

const maxScroll: Position = getMaxScroll({
scrollHeight: doc.scrollHeight,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It turns out these properties are super slow to read sometimes

@@ -49,6 +49,10 @@ export default class AuthorApp extends Component<Props, State> {
return;
}

if (result.destination.index === result.source.index) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

A little optimisation for our storybooks

@@ -30,7 +33,18 @@ import type {
} from '../../../src/types';

const preset = getPreset();
const origin: Position = { x: 0, y: 0 };

const scrolledViewport: Viewport = createViewport({
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

much clearer now

scrollHeight: viewport.height,
scrollWidth: viewport.width,
});
const unscrollableViewport: Viewport = {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yum

@@ -0,0 +1,110 @@
// @flow
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

improved helpers

Copy link
Collaborator Author

@alexreardon alexreardon left a comment

Choose a reason for hiding this comment

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

✌️

@alexreardon alexreardon self-assigned this Mar 4, 2018
Copy link
Contributor

@jaredcrowe jaredcrowe left a comment

Choose a reason for hiding this comment

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

👍

@alexreardon alexreardon merged commit 3e9ba9c into master Mar 5, 2018
@alexreardon alexreardon deleted the less-dom-reads branch March 5, 2018 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants