Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 18, 2025

Hovering over constituencies shows noticeable lag when visualizing 50+ areas. The delay manifests as a visible pause when moving the cursor between adjacent features.

Changes

Remove debounce delay

  • Eliminated 100ms debounce on hover area updates
  • Removed redundant debouncedHoverArea state variable

Memoize expensive computations

  • Cache Mapbox expression evaluations for area colors using useMemo with Map-based lookup
  • Memoize areasToDisplay array to prevent invalidating color cache on unrelated renders

Optimize feature state updates

  • Skip map feature state updates when hovering within the same feature (previously updated on every mousemove)
// Before: Expression evaluated on every render for every area
const getAreaColor = (area) => {
  const colorResult = fillColorExpression.evaluate(/* ... */);
  return toRGBA(colorResult);
};

// After: Memoized, evaluated once per area when dependencies change
const areaColors = useMemo(() => {
  const colors = new Map();
  for (const area of areasToDisplay) {
    colors.set(areaKey, toRGBA(fillColorExpression.evaluate(/* ... */)));
  }
  return colors;
}, [areasToDisplay, areaStats, fillColorExpression, result]);

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits December 18, 2025 13:56
…alculations

Co-authored-by: ev-sc <4164774+ev-sc@users.noreply.github.com>
Co-authored-by: ev-sc <4164774+ev-sc@users.noreply.github.com>
Co-authored-by: ev-sc <4164774+ev-sc@users.noreply.github.com>
Co-authored-by: ev-sc <4164774+ev-sc@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix performance lag in alternative area display Optimize hover performance for large datasets (50+ areas) Dec 18, 2025
Copilot AI requested a review from ev-sc December 18, 2025 14:00
@ev-sc ev-sc marked this pull request as ready for review December 18, 2025 16:30
@ev-sc ev-sc merged commit 4a887c1 into vibe/alternative-areadata-display Dec 18, 2025
@ev-sc ev-sc deleted the copilot/sub-pr-255 branch December 18, 2025 16:30
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.

3 participants