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

Handles the case where a partially buffered nested value is skipped; ensures that fully-buffered containers do not cause the cursor to enter unchecked mode unless stepped into. #692

Merged
merged 1 commit into from
Jan 9, 2024

Conversation

tgregg
Copy link
Contributor

@tgregg tgregg commented Jan 9, 2024

Description of changes:

The two issues mentioned in the PR title can be considered separately:

  1. Handles the case where a partially buffered nested value is skipped. In this case, skipping the nested value involves skipping bytes directly from the input source, using InputStream.skip. Whenever bytes are skipped directly from the input source without being buffered, the marked end indices for any parent containers need to be shifted left (since the indices refer to positions in the buffer, which will no longer contain all of the container's bytes). Before this fix, shiftContainerEnds was not being called in the case where a nested container was skipped before being fully buffered. After this fix, shiftContainerEnds is moved into slowSeek, allowing for individual invocations to be removed. This fix is covered by the following new tests: shouldNotFailWhenAnUnbufferedNestedContainerIsSkipped, shouldNotFailWhenAnUnbufferedNestedContainerIsSteppedOutEarly.
  2. Ensures that fully-buffered containers do not cause the cursor to enter unchecked mode unless stepped into. The binary cursor includes an optimization where it can enter "unchecked" mode (allowing it to avoid bounds checking / buffer refill branching) when the current container is known to be fully buffered. Before this fix, unchecked mode would be entered after reading the container's length, but before stepping into that container. This would cause problems in the case where that container was never stepped into, because the reader would not subsequently exit unchecked mode, leading to the possibility of exhausting the bytes in the buffer without attempting to refill. After this fix, unchecked mode is only activated when the user attempts to step into a fully-buffered container. Upon stepping out, the reader will correctly deactivate unchecked mode. This fix is covered by the following tests: nestedNullContainerIsParsedSuccessfully, nestedEmptyContainerIsParsedSuccessfully, nestedContainerIsSkippedSuccessfully, nestedContainerIsSteppedOutEarlySuccessfully.

These fixes are performance-neutral.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

…ensures that fully-buffered containers do not cause the cursor to enter unchecked mode unless stepped into.
Copy link

codecov bot commented Jan 9, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (140761a) 67.24% compared to head (6754ba1) 67.23%.

Files Patch % Lines
...main/java/com/amazon/ion/impl/IonCursorBinary.java 80.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #692      +/-   ##
============================================
- Coverage     67.24%   67.23%   -0.02%     
+ Complexity     5487     5482       -5     
============================================
  Files           159      159              
  Lines         23019    23016       -3     
  Branches       4126     4124       -2     
============================================
- Hits          15480    15475       -5     
- Misses         6257     6258       +1     
- Partials       1282     1283       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tgregg tgregg merged commit ebf8f4d into master Jan 9, 2024
10 of 35 checks passed
@tgregg tgregg deleted the container-buffering branch January 9, 2024 23:12
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