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

task/WG-432 rework hooks, maps and feature tree to minimize renders #339

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

nathanfranklin
Copy link
Collaborator

Overview:

This PR reworked hooks, maps and feature tree to minimize renders and optimize things.

The main issues we noticed were:

  • flickering of points on map when clicking through panels.
  • slowness when selecting features on map for large datasets.
  • slowness when selecting features on assets panel (FeatureFileTree) for large datasets.
  • very increased render times when loading assets panel and then clicking another panel and then back to assets panel

The fixes were:

  • FixuseCurrentFeatures hook so that provides stable reference to the latest features
  • Fix useFeatureSelection hook to ensure that setSelectedFeatureID is not dependent on selectedFeatureId
  • Added work-around for issue with the height calculation of FeatureFileTree that was causing the tree's virtualization not towork on a component remount
  • Refactor panel components into MapProjectPanelContent
  • -----above changes were the main issues; not 100% if things below were truly needed in this exact form -----
  • Various optimizations to Map
  • Various optimizations to FeatureTree

Off-topic change:

  • Exclude questionnaireBuilder.ts from test coverage calculation

PR Status:

  • Ready.

Related Jira tickets:

Summary of Changes:

Testing Steps:

  1. Load a map with lots of points (try 5000 points from here https://pprd.designsafe-ci.org/data/browser/projects/PRJ-4185/workdir/%2Fgeojson_good)
  2. Try selecting points using map and using asset feature list.
  3. Click various panels and watch map as well as performance
  4. Refresh app when different panels are active and different features selected.

Notes:

TODO

  • bug on initial load of panel if no feature selected; nothing is shown.

Moving functions out of the render cycle and into memoized component properties. Changes
account for feature selection time from 700ms to 20ms
Prevent unnecessary re-renders by removing searchParams dependency as
selectedFeatureId is enough.

Also useMemo for selectedFeatureId determination
Ensure that setSelectedFeatureID is not dependent on selectedFeatureId
Make some optimizations in Map and FeatureFileTree
Copy link
Contributor

@rstijerina rstijerina left a comment

Choose a reason for hiding this comment

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

LGTM

const { height, ref } = useResizeDetector();
const { height: rawHeight, ref } = useResizeDetector({
refreshMode: 'debounce',
refreshRate: 50, // Small debounce to avoid initial extreme values seen on comonent remount
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
refreshRate: 50, // Small debounce to avoid initial extreme values seen on comonent remount
refreshRate: 50, // Small debounce to avoid initial extreme values seen on component remount

Comment on lines +150 to +154
const prevDataRef = useRef<FeatureCollection | undefined>(undefined);
const prevStateRef = useRef<{ pending: boolean; error: boolean }>({
pending: false,
error: false,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, I wonder if react query's keepPreviousData could be of use here?

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