Skip to content

fix: Improve symbol reference/definition list perf #327

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

Merged
merged 2 commits into from
Jun 2, 2025

Conversation

brendan-kellam
Copy link
Contributor

@brendan-kellam brendan-kellam commented Jun 2, 2025

I noticed some perf issues when rendering large reference lists. This PR adds virtual scrolling to address this.

Summary by CodeRabbit

  • New Features
    • Added a character limit for code previews, displaying a user-friendly message if a file is too large to preview.
  • Bug Fixes
    • Improved performance for large reference and definition lists by virtualizing list rendering.
  • Documentation
    • Updated changelog to reflect the fix for slow rendering of large lists.

Copy link

coderabbitai bot commented Jun 2, 2025

Walkthrough

The changes introduce performance improvements and user experience enhancements for handling large code and reference lists. A character limit is enforced for code previews, displaying a fallback message for oversized files. The reference list component is refactored to use virtualization, rendering only visible items for better scalability. The changelog is updated to reflect these fixes.

Changes

File(s) Change Summary
CHANGELOG.md Added entry for fix addressing slow rendering of large reference and definition lists.
.../components/lightweightCodeHighlighter.tsx Enforced 1000-character line limit for previews; displays fallback message if exceeded; UI adjustment.
.../features/codeNav/components/exploreMenu/referenceList.tsx Refactored to use virtualized list rendering for improved performance with large datasets.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant LightweightCodeHighlighter
    participant ReferenceList

    User->>LightweightCodeHighlighter: Load code preview
    LightweightCodeHighlighter->>LightweightCodeHighlighter: Check line lengths
    alt Any line > 1000 chars
        LightweightCodeHighlighter-->>User: Show "File too large to display in preview."
    else
        LightweightCodeHighlighter->>LightweightCodeHighlighter: Highlight and render code
        LightweightCodeHighlighter-->>User: Show code preview
    end

    User->>ReferenceList: Open reference/definition list
    ReferenceList->>ReferenceList: Initialize virtualizer
    loop On scroll/viewport change
        ReferenceList->>ReferenceList: Render only visible file/match rows
    end
    ReferenceList-->>User: Display virtualized reference list
Loading

Poem

🐇
When lists grow tall and code lines sprawl,
I hop to help and fix them all.
With virtual scroll and limits set,
No lags or crashes, you can bet!
Now previews shine and lists stay spry—
A happy bunny coding by.
🌱

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

msukkari
msukkari previously approved these changes Jun 2, 2025
…d display a message that the file could not be rendered
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/web/src/app/[domain]/components/lightweightCodeHighlighter.tsx (1)

55-57: Minor optimization: Improve memoization dependency.

The memoization should depend on unhighlightedLines instead of code for better accuracy since unhighlightedLines is the actual processed data being checked.

const isFileTooLargeToDisplay = useMemo(() => {
    return unhighlightedLines.some(line => line.length > MAX_NUMBER_OF_CHARACTER_PER_LINE);
-}, [code]);
+}, [unhighlightedLines]);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 81a9ea1 and 54ba104.

📒 Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • packages/web/src/app/[domain]/components/lightweightCodeHighlighter.tsx (3 hunks)
  • packages/web/src/ee/features/codeNav/components/exploreMenu/referenceList.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: build
🔇 Additional comments (11)
CHANGELOG.md (1)

12-12: LGTM! Changelog entry correctly documents the performance fix.

The changelog entry properly documents the performance improvement for large reference/definition lists and correctly references this PR.

packages/web/src/app/[domain]/components/lightweightCodeHighlighter.tsx (4)

30-31: Good performance safeguard with reasonable limit.

The 1000 character limit per line is a sensible threshold for preventing performance issues in code previews while still accommodating most typical code lines.


64-66: Excellent early return optimization.

The early return prevents unnecessary processing when files are too large, which is exactly what's needed for performance improvement.


116-122: Clear and user-friendly fallback message.

The fallback UI provides a clear explanation to users when files are too large to display, maintaining good UX while protecting performance.


130-130: Good addition for handling long content.

The wordBreak: 'break-all' style helps handle long lines visually, complementing the character limit safeguard.

packages/web/src/ee/features/codeNav/components/exploreMenu/referenceList.tsx (6)

9-11: Good virtualization imports for performance improvement.

The addition of useRef and useVirtualizer from @tanstack/react-virtual are the right choices for implementing efficient list virtualization.


18-19: Reasonable size estimates for virtualization.

The estimated heights (30px for lines and matches) provide a good starting point for the virtualizer. These will be refined as actual measurements are taken during rendering.


37-51: Excellent virtualization configuration.

The virtualizer setup is well-configured with:

  • Dynamic size estimation based on match count
  • Proper overscan for smooth scrolling
  • Enabled measurement for accurate sizing

This should significantly improve performance for large reference lists.


87-90: Clever sticky header positioning solution.

The negative top positioning (top: -${virtualRow.start}px) is an elegant solution to maintain sticky headers within the virtualized container while preserving the visual hierarchy.


53-62: Good performance optimizations in container styling.

The container styling with contain: 'strict' and proper overflow handling optimizes rendering performance by creating an isolated rendering context.


70-131: Comprehensive virtualization implementation preserves all functionality.

The virtual item rendering successfully maintains all original features:

  • File headers with repository information
  • Sorted matches by line number
  • Click navigation functionality
  • Proper event tracking

This is a well-executed refactor that should provide significant performance improvements for large lists while maintaining full compatibility.

@brendan-kellam brendan-kellam merged commit 91e803d into main Jun 2, 2025
5 checks passed
@brendan-kellam brendan-kellam deleted the bkellam/improve_reference_list_perf branch June 2, 2025 21:49
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