Skip to content

⚡ [Performance] Virtualize Connections List#408

Open
Asutorufa wants to merge 4 commits intomainfrom
perf/virtualize-connections-list-17591614436217613194
Open

⚡ [Performance] Virtualize Connections List#408
Asutorufa wants to merge 4 commits intomainfrom
perf/virtualize-connections-list-17591614436217613194

Conversation

@Asutorufa
Copy link
Collaborator

  • 💡 What: Replaced the standard mapped list with react-window's FixedSizeList in src/docs/connections/v2/page.tsx.
  • 🎯 Why: To improve rendering performance when thousands of connections are active. Rendering 2000+ complex motion.li components caused significant lag and high memory usage.
  • 📊 Implementation Details:
    • Used FixedSizeList for O(1) rendering relative to viewport.
    • Implemented responsive row heights (Mobile/Desktop) using useWindowWidth.
    • Refactored Connections page layout to use flexbox and ResizeObserver (via useContainerDimensions) to ensure the list fills the available vertical space correctly.
    • Removed AnimatePresence and entry/exit animations for list items as they are incompatible with virtualization performance goals, but retained hover effects.
    • Created (and then cleaned up) a benchmark reproduction script benchmark_repro.tsx which confirmed the O(N) mounting cost of the original implementation.
  • ⚠️ Verification Note: Due to the lack of a running backend in the CI environment, frontend verification via screenshot was skipped, but the logic was verified through code analysis and unit-level reasoning.

PR created automatically by Jules for task 17591614436217613194 started by @Asutorufa

- Replace mapped list with react-window FixedSizeList
- Add useContainerDimensions and useWindowWidth hooks for responsive sizing
- Refactor page layout to flex column for proper list containment
- Remove heavy entry/exit animations for list items

Co-authored-by: Asutorufa <16442314+Asutorufa@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Asutorufa, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request delivers a crucial performance upgrade to the connections list by integrating react-window for UI virtualization. This change dramatically reduces rendering overhead and memory consumption when dealing with a large number of connections, ensuring a smoother user experience. It also includes necessary layout adjustments and the removal of conflicting animations to fully leverage the benefits of virtualization across different screen sizes.

Highlights

  • Performance Enhancement: Replaced a standard mapped list with react-window's FixedSizeList to significantly improve rendering performance for thousands of connections, addressing previous lag and high memory usage.
  • Responsive Layout & Sizing: Implemented responsive row heights for mobile and desktop views using a new useWindowWidth hook. The page layout was refactored with flexbox and a ResizeObserver (via useContainerDimensions) to ensure the virtualized list correctly fills available vertical space.
  • Animation Optimization: Removed framer-motion's AnimatePresence and associated entry/exit animations from list items, as they were incompatible with the performance goals of virtualization. Hover effects have been retained.
  • Custom React Hooks: Introduced two new custom React hooks: useContainerDimensions for observing the dimensions of a DOM element and useWindowWidth for tracking the browser window's width, enabling dynamic UI adjustments.
Changelog
  • src/docs/connections/v2/page.tsx
    • Removed imports for AnimatePresence and motion from framer-motion.
    • Added imports for useEffect, useRef from react and FixedSizeList, ListChildComponentProps from react-window.
    • Modified the root div of the Connections component to use flex flex-col h-full overflow-hidden for a flexible, full-height layout.
    • Wrapped FlowContainer and the sort/filter controls in divs with shrink-0 to prevent them from shrinking.
    • Wrapped the ConnectionList component in a div with flex-1 min-h-0 relative to allow it to expand and fill available vertical space.
    • Replaced the ul based rendering of ConnectionListComponent with react-window's FixedSizeList.
    • Introduced containerRef to measure the parent container's dimensions for FixedSizeList.
    • Implemented useContainerDimensions custom hook using ResizeObserver to dynamically get container width and height.
    • Implemented useWindowWidth custom hook to determine the current window width for responsive item sizing.
    • Defined itemSize dynamically based on whether the view is mobile or desktop.
    • Created a new Row functional component to render individual connection items, which is passed to FixedSizeList.
    • Removed layout, initial, animate, exit, and transition props from list items, as framer-motion animations are no longer used.
Activity
  • The pull request was automatically created by Jules for task 17591614436217613194, initiated by @Asutorufa.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses a performance bottleneck by virtualizing the connections list using react-window. The implementation is solid, correctly using ResizeObserver and flexbox to create a responsive, dynamically-sized list. The code is clean and the approach is sound. I've added a couple of suggestions to further improve the new utility hooks for better maintainability and to optimize for performance by preventing unnecessary re-renders. Overall, this is an excellent enhancement.

Comment on lines +342 to +346
const observer = new ResizeObserver(entries => {
if (!entries || entries.length === 0) return;
const { width, height } = entries[0].contentRect;
setDimensions({ width, height });
});
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To prevent unnecessary re-renders, it's a good practice to update the state only when the dimensions have actually changed. The current implementation creates a new object for dimensions on every ResizeObserver callback, which will always trigger a re-render of the component using this hook, even if the size is identical.

        const observer = new ResizeObserver(entries => {
            if (!entries?.[0]) return;
            const { width, height } = entries[0].contentRect;
            setDimensions(currentDimensions => {
                if (currentDimensions.width === width && currentDimensions.height === height) {
                    return currentDimensions;
                }
                return { width, height };
            });
        });
References
  1. To prevent unnecessary re-renders, ensure that state updates for objects only occur when the values actually change, and return the existing object reference if no change is detected. This aligns with the principle of maintaining stable references to prevent re-renders, similar to how useMemo should return stable object references.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

medium

To prevent unnecessary re-renders, it's a good practice to update the state only when the dimensions have actually changed. The current implementation creates a new object for dimensions on every ResizeObserver callback, which will always trigger a re-render of the component using this hook, even if the size is identical.

        const observer = new ResizeObserver(entries => {
            if (!entries?.[0]) return;
            const { width, height } = entries[0].contentRect;
            setDimensions(currentDimensions => {
                if (currentDimensions.width === width && currentDimensions.height === height) {
                    return currentDimensions;
                }
                return { width, height };
            });
        });

References

@jules

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

medium

To prevent unnecessary re-renders, it's a good practice to update the state only when the dimensions have actually changed. The current implementation creates a new object for dimensions on every ResizeObserver callback, which will always trigger a re-render of the component using this hook, even if the size is identical.

        const observer = new ResizeObserver(entries => {
            if (!entries?.[0]) return;
            const { width, height } = entries[0].contentRect;
            setDimensions(currentDimensions => {
                if (currentDimensions.width === width && currentDimensions.height === height) {
                    return currentDimensions;
                }
                return { width, height };
            });
        });

References

@jules

Copy link
Contributor

Choose a reason for hiding this comment

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

Updated useContainerDimensions in src/common/hooks.ts to only update state when dimensions actually change, preventing unnecessary re-renders.

Copy link
Contributor

Choose a reason for hiding this comment

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

Updated useContainerDimensions to implement the suggested state update optimization.

google-labs-jules bot and others added 3 commits February 9, 2026 08:54
- Replace mapped list with react-window FixedSizeList for O(1) rendering
- Move useContainerDimensions and useWindowWidth to src/common/hooks.ts
- Refactor Connections page layout to flex column for proper list containment
- Remove heavy entry/exit animations for list items

Co-authored-by: Asutorufa <16442314+Asutorufa@users.noreply.github.com>
- Update import from FixedSizeList to List to match installed react-window version

Co-authored-by: Asutorufa <16442314+Asutorufa@users.noreply.github.com>
- Implement state update optimization in useContainerDimensions to prevent unnecessary re-renders when dimensions remain unchanged.

Co-authored-by: Asutorufa <16442314+Asutorufa@users.noreply.github.com>
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.

1 participant