Fix zero-hash memoization gap in ExpressionBase.hashCode() - #2
Draft
jaipilot[bot] wants to merge 1 commit into
Draft
Fix zero-hash memoization gap in ExpressionBase.hashCode()#2jaipilot[bot] wants to merge 1 commit into
jaipilot[bot] wants to merge 1 commit into
Conversation
Owner
|
Accepted for the JAIPilot evidence campaign — additional success 8/10 after the ShardingSphere anchor. Independent review:
Boundary: the real-world gain is intentionally narrow—it applies when an expression’s legitimate computed hash is exactly zero. This is counted for correctness of memoization plus deterministic eliminated work, not as a broad throughput claim. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The original PR (OpenFeign#1897 upstream) removed boxed
Integerstorage fromExpressionBase.hashCode()in favor of a primitiveint, using0as the 'uncomputed' sentinel. A legitimately computed hash of0(e.g.Expressions.constant(0), or anyPath/Operationwhose metadata/args happen to hash to0) is therefore never memoized: every call tohashCode()rerunsHashCodeVisitorfrom scratch.Fix
Added a second
transient volatile boolean hashCodeComputedflag that marks completion independently of the stored value.hashCode():intonce; if non-zero, returns immediately (identical to the PR-head fast path: one volatile read, no extra field access).hashCodeComputed. If true, re-reads the (now guaranteed fresh)hashCodefield instead of trusting the stale local snapshot from step 1, and returns it.HashCodeVisitor, stores it, sets the flag, and returns it.Preserved
int,boolean).transient; neither is part of serialized state, matching the existingtoStringfield pattern.hashCode()signature and semantics unchanged.Evidence
ExpressionBaseTest(added before the production edit) passes identically, with the same command, against the original PR-head implementation and the candidate.HashCodeVisitorinvocations per 5hashCode()calls on a zero hash before the fix, and 1 invocation after, across 5 repeated runs each; the non-zero case stays at 1 invocation for both.no-databasesbuild (all 27 modules) passes with the candidate.Limitations
Generated by JAIPilot Cloud for #1 from Anthropic session
sesn_01B6hwFRezpzFTCZnAhcrrZq.