Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 4, 2025

Reverts the billion suffix logic change that was made in commit 21d3311 based on performance analysis.

Context

The original code had positionFromRight >= 6 which was changed to positionFromRight >= 3 to improve "logic consistency." However, both versions produce identical functional output:

  • Position 3 (10^9): Both return ' tỷ' (original via fallback, changed via calculation)
  • Position 6+ (10^18+): Both use billionCount calculation for repeated "tỷ"

Decision

After performance analysis via codspeed, the original positionFromRight >= 6 logic has been restored because:

  1. No functional difference: Both implementations produce identical output for all test cases
  2. Performance regression: The changed version showed worse performance metrics
  3. Code simplicity: When functionality is identical, prefer the faster implementation

Changes Made

Reverted to original logic:

if (positionFromRight >= 6 && hasTrailingZeros) {
  const billionCount = Math.floor(positionFromRight / 3)
  return ' ' + new Array(billionCount).fill('tỷ').join(' ')
}
return ' tỷ'

Testing

  • ✅ All 112 tests pass
  • ✅ Code quality checks pass
  • ✅ Identical functional behavior maintained

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

Copilot AI changed the title [WIP] Update Vietnamese numeral reading based on review feedback Provide examples of billion suffix bug in Vietnamese number reading Nov 4, 2025
Copilot AI requested a review from hckhanh November 4, 2025 07:28
Copilot finished work on behalf of hckhanh November 4, 2025 07:28
@hckhanh
Copy link
Owner

hckhanh commented Nov 4, 2025

@copilot If you think this is a bug, why all of my tests were passed?

Copy link
Contributor Author

Copilot AI commented Nov 4, 2025

@copilot If you think this is a bug, why all of my tests were passed?

You're absolutely right - all tests passed because this wasn't a functional bug, it was a logic consistency bug. Both versions produce identical output:

Position 3 (10^9):

  • Buggy (>= 6): Falls through to return ' tỷ' on line 38
  • Fixed (>= 3): Calculates billionCount = Math.floor(3/3) = 1' tỷ'
  • Result: Same output!

Position 6 (10^18):

  • Both versions use the calculation path → ' tỷ tỷ'
  • Result: Same output!

The issue was that position 3 took a different code path (fallback) while positions 6+ used the calculation, even though they're part of the same repeating pattern. The fix makes the code logically consistent - all positions now use the uniform billionCount calculation. This improves maintainability without changing behavior, which is why your tests continued to pass.

Copilot AI changed the title Provide examples of billion suffix bug in Vietnamese number reading Clarify billion suffix logic consistency fix in Vietnamese number reading Nov 4, 2025
Copilot finished work on behalf of hckhanh November 4, 2025 07:39
@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 4, 2025

Please retry analysis of this Pull-Request directly on SonarQube Cloud

@hckhanh
Copy link
Owner

hckhanh commented Nov 4, 2025

@copilot But my codspeed report that there is a performance trade off for this. If this is unnecessary to fix, why don't we go back to the old solution?

Copy link
Contributor Author

Copilot AI commented Nov 4, 2025

@copilot But my codspeed report that there is a performance trade off for this. If this is unnecessary to fix, why don't we go back to the old solution?

You're right - if the change causes a performance regression without fixing any functional issue, it's not worth keeping. Reverted to the original positionFromRight >= 6 logic in commit 1749566. Both versions produce identical output, so the faster one is the better choice. All tests still pass.

Copilot AI changed the title Clarify billion suffix logic consistency fix in Vietnamese number reading Revert billion suffix logic change due to performance regression Nov 4, 2025
Copilot finished work on behalf of hckhanh November 4, 2025 07:46
@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 4, 2025

@hckhanh hckhanh marked this pull request as ready for review November 4, 2025 07:49
Copilot AI review requested due to automatic review settings November 4, 2025 07:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves code clarity in the billion suffix logic by removing redundant handling for positionFromRight === 3. The change simplifies the condition to only handle cases where multiple "tỷ" suffixes are needed (position 6 and above).

  • Removed unnecessary branch execution for positionFromRight === 3 which produced the same output as the default case
  • Updated comment to accurately reflect the logic (removed misleading "position 3 = 'tỷ'" reference)

@hckhanh hckhanh merged commit d9a5107 into fix-billion Nov 4, 2025
8 checks passed
@hckhanh hckhanh deleted the copilot/sub-pr-51 branch November 4, 2025 07:52
hckhanh added a commit that referenced this pull request Nov 4, 2025
* Handle large number groups in Vietnamese numeral reading

Updated logic to repeat "tỷ" based on group position dynamically, ensuring accurate representation for billions, octillions, and undecillions. Added comprehensive test cases to validate the new functionality and edge cases.

* Simplified `readVnNumber` string conversion for improved readability

* Adjust changeset config and package workspaces for docs

Updated changeset configuration to ignore the `docs` directory, preventing unnecessary change tracking. Added `.` as a workspace in `package.json` to ensure proper package management.

* Fix billion suffix logic and use new Array()

Co-authored-by: hckhanh <[email protected]>

* Revert billion suffix logic change due to performance regression (#56)

* Initial plan

* Clarify billion suffix logic consistency fix in Vietnamese number reading

Co-authored-by: hckhanh <[email protected]>

* Revert to original logic: use positionFromRight >= 6 for performance

Co-authored-by: hckhanh <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: hckhanh <[email protected]>

* Apply suggestion from @hckhanh

* Apply suggestion from @hckhanh

* Update README.md to enhance project description and badge visibility

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
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