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

Improve optimization progress accuracy #2538

Merged
merged 1 commit into from
Nov 13, 2024

Conversation

TornOne
Copy link
Contributor

@TornOne TornOne commented Nov 10, 2024

Describe your changes

Updated the progress bar when optimizing artifacts to better reflect the actual percentage of progress done.
The new formula is based on the assumption that the amount of skipped builds remains proportional to the amount of tested builds, but also improves accuracy in cases where more builds are skipped closer to the end than the beginning, and cases where not too many more builds are skipped closer to the beginning than the end.
In contrast, the previous formula essentially assumed all builds that were going to be skipped were skipped as soon as the generation started.

Issue or discord link

https://discord.com/channels/785153694478893126/1296108919608971334

Checklist before requesting a review (leave this PR as draft if any part of this list is not done.)

  • I have commented my code in hard-to understand areas.
  • I have made corresponding changes to README or wiki.
  • For front-end changes, I have updated the corresponding English translations.
  • I have run yarn run mini-ci locally to validate format and lint.
  • If I have added a new library or app, I have updated the deployment scripts to ignore changes as needed

Summary by CodeRabbit

  • New Features
    • Updated progress calculation in the Build Alert to include skipped builds, providing a more accurate representation of build status.
  • Bug Fixes
    • Improved display of progress percentage in the Build Alert based on the new calculation method.

Copy link
Contributor

coderabbitai bot commented Nov 10, 2024

Walkthrough

The pull request modifies the calculation of the progress variable in the BuildAlert function across two files. The previous formula, which calculated progress based on tested builds relative to unskipped builds, has been updated to include skipped builds in the total calculation. This change affects how progress is displayed in the alert but does not alter the overall structure, parameters, or error handling of the function.

Changes

File Path Change Summary
libs/gi/page-team/src/CharacterDisplay/Tabs/TabOptimize/Components/BuildAlert.tsx Updated progress calculation to include skipped builds: now ((tested + skipped) / total) * 100. Adjusted title and subtitle variables accordingly.
libs/gi/ui/src/components/character/BuildAlert.tsx Updated progress calculation to include skipped builds: now ((tested + skipped) / total) * 100. No changes to function structure or error handling.

Suggested reviewers

  • frzyc
  • nguyentvan7

🐇 In the land of builds, where progress is key,
A change was made, oh so cleverly!
From tested to total, now all is in sight,
Skipped builds counted, oh what a delight!
Alerts now shine with a new kind of glow,
Hopping along, watch the progress grow! 🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 64a5339 and 430afc0.

📒 Files selected for processing (2)
  • libs/gi/page-team/src/CharacterDisplay/Tabs/TabOptimize/Components/BuildAlert.tsx (1 hunks)
  • libs/gi/ui/src/components/character/BuildAlert.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • libs/gi/page-team/src/CharacterDisplay/Tabs/TabOptimize/Components/BuildAlert.tsx
  • libs/gi/ui/src/components/character/BuildAlert.tsx

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • 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 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.

Copy link
Contributor

@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

🧹 Outside diff range and nitpick comments (1)
libs/gi/ui/src/components/character/BuildAlert.tsx (1)

72-72: LGTM! Consider adding a clarifying comment.

The new progress calculation (tested + skipped) / total * 100 correctly implements the proportional progress tracking, assuming that skipped builds are distributed throughout the optimization process rather than front-loaded.

Consider adding a comment to explain this assumption:

+    // Assume skipped builds are proportionally distributed throughout the process
     progress = (tested + skipped) / total * 100
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c23eaf1 and 64a5339.

📒 Files selected for processing (2)
  • libs/gi/page-team/src/CharacterDisplay/Tabs/TabOptimize/Components/BuildAlert.tsx (1 hunks)
  • libs/gi/ui/src/components/character/BuildAlert.tsx (1 hunks)
🔇 Additional comments (2)
libs/gi/page-team/src/CharacterDisplay/Tabs/TabOptimize/Components/BuildAlert.tsx (2)

Line range hint 58-65: LGTM: Progress display logic aligns with PR objectives.

The updated progress calculation and display logic correctly implements the new approach where:

  1. Skipped builds are considered part of progress
  2. Progress more accurately reflects the actual state of optimization
  3. The UI updates maintain consistency with the numerical changes

58-58: Verify edge cases in progress calculation.

The new formula (tested + skipped) / total * 100 better reflects actual progress by including skipped builds proportionally. However, we should ensure it handles edge cases gracefully.

Consider adding a guard clause:

-    progress = (tested + skipped) / total * 100
+    progress = total > 0 ? Math.min((tested + skipped) / total * 100, 100) : 0
✅ Verification successful

Progress calculation is safe and correctly implemented

The progress calculation is already protected by sufficient guards:

  1. The calculation only runs within the if (generatingBuilds) block
  2. The BuildStatus type ensures all required values (tested, skipped, total) are non-optional numbers
  3. The total is initialized to 0 in the parent component when inactive, preventing division by zero scenarios

The new formula (tested + skipped) / total * 100 is mathematically sound and correctly reflects the proportional progress including skipped builds.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for potential edge cases in progress calculation
# Look for places where total, tested, or skipped might be 0 or undefined

# Test 1: Check if total can be 0 or undefined
rg -A 5 "total\s*=\s*[0]|total\s*=\s*undefined" 

# Test 2: Look for error handling around the division
rg -A 5 "total.*===.*0|total.*==.*0|!total"

Length of output: 1073


Script:

#!/bin/bash
# Let's examine the BuildAlert component more thoroughly to understand the progress calculation context

# Look for the component definition and props
ast-grep --pattern 'interface BuildAlertProps {
  $$$
}'

# Check how tested, skipped, and total are derived
rg -B 5 -A 5 "progress\s*=.*tested.*skipped.*total"

# Look for any existing guards or error handling
rg -B 3 -A 3 "const.*{.*tested.*skipped.*total"

Length of output: 2548


Script:

#!/bin/bash
# Let's check how the variables are destructured and if there are any guards
rg -B 3 -A 3 "const.*\{.*tested.*skipped.*\}"

# Check if generatingBuilds has any guards
rg -B 3 -A 3 "if.*generatingBuilds.*\{"

# Look for the type definition of the build status
ast-grep --pattern 'type BuildStatus = {
  $$$
}'

Length of output: 3915

Copy link
Contributor

github-actions bot commented Nov 10, 2024

[frontend] [Sun Nov 10 16:51:45 UTC 2024] - Deployed 8a576bd to https://genshin-optimizer-prs.github.io/pr/2538/frontend (Takes 3-5 minutes after this completes to be available)

[frontend] [Mon Nov 11 21:59:55 UTC 2024] - Deployed b11e0b6 to https://genshin-optimizer-prs.github.io/pr/2538/frontend (Takes 3-5 minutes after this completes to be available)

[Wed Nov 13 02:05:35 UTC 2024] - Deleted deployment

@TornOne TornOne force-pushed the improve-optimization-progress-accuracy branch from 64a5339 to 430afc0 Compare November 11, 2024 11:05
@lantua
Copy link
Collaborator

lantua commented Nov 12, 2024

What's the behavior for this progress bar if skipped >> unskipped since the beginning? We use the current formula because the previous one got "stuck" at ~99% when skipped is larger than unskipped by several order of magnitudes, which was common at the time (and hopefully is still common nowadays).

@TornOne
Copy link
Contributor Author

TornOne commented Nov 12, 2024

Indeed, if the amount of skipped builds makes up for a large majority of the total builds at the beginning, then the bar will spend more time seemingly near completion, as you said.
I have never seen this happen since some update to the the way the artifacts were processed some years back. I have also tested this is with a "normal" batch of artifacts, and the behavior seems to remain exactly the same, so my unique common usage of GO should not be a factor.

I am curious if you could provide examples of the behavior you describe happening in real-world use, because in my experience, the opposite is somewhat common currently - the bar gets "stuck" at 0%, spending 10-100 times (this depends on how many more builds are skipped than unskipped) more time going from 0% to 1% than from 99% to 100%. I would hope the change fixes this dramatic "speedup" I regularly see.

@lantua
Copy link
Collaborator

lantua commented Nov 13, 2024

I couldn't find the old benchmark data, and we don't have a perf test either :D
When I said there would be many prunings at the beginning, I may have been thinking about the "first prune" (one before Solver instantiation), but that shouldn't affect this PR.

A more recent test has around 3x pruning instead, and this PR should work fine enough.

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