Skip to content

Revert "Fix Python VarIntCoder OverflowError on uint64 values"#39218

Open
Abacn wants to merge 1 commit into
masterfrom
revert-39047-fix-varintcoder-uint64
Open

Revert "Fix Python VarIntCoder OverflowError on uint64 values"#39218
Abacn wants to merge 1 commit into
masterfrom
revert-39047-fix-varintcoder-uint64

Conversation

@Abacn

@Abacn Abacn commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Reverts #39047 due to performance regression

encoding values>INT_MAX with varint coder is undefined behavior. Guarding it at the cost of performance degradation isn't preferred

more context: #39047 (comment)

closes #39216

@github-actions github-actions Bot added the python label Jul 6, 2026
@Abacn

Abacn commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

R: @jrmccluskey

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment assign set of reviewers

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 reverts a previous change that aimed to fix Python VarIntCoder OverflowError on uint64 values. The reversion is necessary due to an identified performance regression caused by the previous implementation. The changes effectively restore the previous behavior where the coder is limited to 64-bit signed integers.

Highlights

  • Reversion of uint64 handling: This PR reverts the changes that attempted to handle uint64 values in VarIntCoder, as it introduced a performance regression.
  • Removal of helper functions: The _as_signed_int64 helper function and associated logic for folding uint64 values into signed int64 have been removed.
  • Test cleanup: The test_varint_coder_uint64 test case has been removed as it is no longer applicable following the reversion.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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

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.

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

Copy link
Copy Markdown
Contributor

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 simplifies VarIntCoderImpl by removing the folding of uint64 values into signed int64 integers, restricting the coder strictly to 64-bit signed integers. Feedback suggests wrapping the type cast in encode with a try...except block to prevent Cython from raising an unhandled OverflowError before reaching the custom error handling. Additionally, it is recommended to add a test case verifying that out-of-range values correctly raise an OverflowError to maintain test coverage after the removal of test_varint_coder_uint64.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines 1059 to 1063
def encode(self, value):
# Compare as a Python object: a uint64 value overflows the int64_t cast
# the compiled fast path used to do here. Non-small values (including
# uint64) fall through to encode_to_stream, which folds them.
if 0 <= value < len(small_ints):
return small_ints[value]
ivalue = value # type cast
if 0 <= ivalue < len(small_ints):
return small_ints[ivalue]
return StreamCoderImpl.encode(self, value)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

In Cython compiled mode, ivalue is declared as int64_t in .pxd. The assignment ivalue = value performs a type cast. If value is an integer that overflows the 64-bit signed integer range, this assignment will raise an OverflowError immediately.

This bypasses the fallback to StreamCoderImpl.encode(self, value) and the custom OverflowError handling in encode_to_stream (lines 1048-1053), which is designed to provide a helpful error message explaining the 64-bit signed integer limit. Instead, the user receives a generic Cython OverflowError.

Wrapping the type cast and small integer check in a try...except OverflowError block allows the overflow to be caught and safely delegated to StreamCoderImpl.encode, which will then raise the descriptive error message.

  def encode(self, value):
    try:
      ivalue = value  # type cast
      if 0 <= ivalue < len(small_ints):
        return small_ints[ivalue]
    except OverflowError:
      pass
    return StreamCoderImpl.encode(self, value)

with self.assertRaises(OverflowError):
coder.encode(v)

def test_varint32_coder(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Since test_varint_coder_uint64 is being removed, we should ensure that we still have test coverage verifying that values outside the supported 64-bit signed integer range (such as 1 << 63, 1 << 64, and -(1 << 63) - 1) correctly raise OverflowError.

Suggested change
def test_varint32_coder(self):
def test_varint_coder_overflow(self):
coder = coders.VarIntCoder()
for v in [1 << 63, 1 << 64, -(1 << 63) - 1]:
with self.assertRaises(OverflowError):
coder.encode(v)
def test_varint32_coder(self):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Performance Regression or Improvement: gbk_python_batch_load_test_2gb_of_100KB_records:runtime

1 participant