Skip to content

fix: resolve the progress bar stuck when build 10k files#161

Merged
chlins merged 1 commit intomainfrom
fix/pb-stuck-with-10k-files
Apr 22, 2025
Merged

fix: resolve the progress bar stuck when build 10k files#161
chlins merged 1 commit intomainfrom
fix/pb-stuck-with-10k-files

Conversation

@chlins
Copy link
Member

@chlins chlins commented Apr 22, 2025

This pull request improves the functionality and efficiency of the ProgressBar implementation in internal/pb/pb.go. The key changes include adding a refresh rate to the progress bar, simplifying the creation of new bars, and improving thread safety by consolidating bar initialization logic.

Enhancements to ProgressBar functionality:

  • Added a time import to support the new refresh rate configuration for the progress bar.
  • Updated the NewProgressBar function to set a refresh rate of 300 milliseconds for the progress bar using mpbv8.WithRefreshRate.

Simplification and thread safety improvements:

  • Refactored the Add method to introduce a progressBar instance (newBar) earlier, consolidating the initialization of the bar and its associated metadata (e.g., msg). This simplifies the logic and reduces redundant code.
  • Replaced the manual creation and assignment of a progressBar instance in the Add method with the pre-initialized newBar, ensuring consistency and thread safety.

Closes #160.

Summary by CodeRabbit

  • Refactor
    • Improved progress bar performance and responsiveness by optimizing the refresh rate and streamlining internal message handling.

@coderabbitai
Copy link

coderabbitai bot commented Apr 22, 2025

"""

Walkthrough

The changes in this pull request modify the internal progress bar implementation by explicitly setting the refresh rate to 300 milliseconds and refactoring the way progress bar messages are handled. The message formatting and storage are now consolidated into a dedicated struct, eliminating redundant locking and map lookups during decorator rendering. The progress bar creation and management logic is streamlined, with the new struct instance stored in the internal map and used for proxy reader creation. There are no changes to exported function or method signatures.

Changes

File(s) Change Summary
internal/pb/pb.go Set progress bar refresh rate to 300ms; refactored message formatting and storage; streamlined bar creation and decorator logic; removed redundant locking and lookups.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant ProgressBar
    participant mpb.Progress
    participant progressBar (struct)
    participant Bar

    Caller->>ProgressBar: Add(size, prompt, name, reader)
    ProgressBar->>progressBar (struct): Create instance with size and formatted msg
    ProgressBar->>mpb.Progress: New(size, decorators)
    mpb.Progress-->>progressBar (struct): Return Bar instance
    progressBar (struct)->>Bar: Store Bar
    progressBar (struct)->>ProgressBar: Store in bars map
    progressBar (struct)->>Bar: ProxyReader(reader)
    Bar-->>Caller: Return proxy reader
Loading

Assessment against linked issues

Objective Addressed Explanation
Prevent program from getting stuck on progress bar refresh with 10k files (#160)

Suggested reviewers

  • gaius-qi

Poem

A hop, a skip, a progress bar anew,
With 10k files, it now breezes through!
No more stuck, no endless wait,
The rabbit’s code is feeling great.
With every tick, the bars advance—
A bug is squashed, let’s do a dance!
🐇✨
"""

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (1.64.8)

Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2
Failed executing command with error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0c9229b and dae87f3.

📒 Files selected for processing (1)
  • internal/pb/pb.go (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/pb/pb.go
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (go)

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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.

@chlins chlins added the bug Something isn't working label Apr 22, 2025
Signed-off-by: chlins <chlins.zhang@gmail.com>
@chlins chlins force-pushed the fix/pb-stuck-with-10k-files branch from 0c9229b to dae87f3 Compare April 22, 2025 03:46
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)
internal/pb/pb.go (1)

89-89: Remove embedded field "Bar" from selector

The linter identified that the embedded field "Bar" could be removed from the selector.

-  return newBar.Bar.ProxyReader(reader)
+  return newBar.ProxyReader(reader)

Since Bar is an embedded field in the progressBar struct, you can access its methods directly without specifying the field name.

🧰 Tools
🪛 GitHub Actions: Lint

[error] 89-89: staticcheck: could remove embedded field "Bar" from selector (QF1008)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3a2aab2 and 0c9229b.

📒 Files selected for processing (1)
  • internal/pb/pb.go (4 hunks)
🧰 Additional context used
🪛 GitHub Actions: Lint
internal/pb/pb.go

[error] 89-89: staticcheck: could remove embedded field "Bar" from selector (QF1008)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (go)
🔇 Additional comments (5)
internal/pb/pb.go (5)

23-23: Good addition of time package

Adding the time package import is necessary to support the new refresh rate setting for the progress bar.


51-51: Great fix for the progress bar stuck issue

Setting a refresh rate of 300ms is an excellent solution to prevent the progress bar from getting stuck when building 10k files. This explicit refresh rate ensures the UI updates at regular intervals regardless of processing speed.


66-67: Good refactoring of progress bar creation

Creating the progressBar instance upfront with the formatted message improves code clarity and maintainability.


68-74: Improved decorator implementation

The simplified decorator function is more efficient as it now directly returns the stored message from the progressBar instance, avoiding lock contention and map lookups during rendering.


86-87: Consistent state management

Storing the new progressBar instance in the map improves code consistency and thread safety.

@BraveY BraveY self-assigned this Apr 22, 2025
Copy link
Contributor

@BraveY BraveY left a comment

Choose a reason for hiding this comment

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

LGTM!

@chlins chlins merged commit bb291a5 into main Apr 22, 2025
6 checks passed
@chlins chlins deleted the fix/pb-stuck-with-10k-files branch April 22, 2025 07:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Program stuck on progress bar with 10k files

2 participants