Avoid fast-path IO writes when IO has ext enc#759
Merged
headius merged 1 commit intoruby:masterfrom Mar 10, 2025
Merged
Conversation
This works around a bug in JRuby's IOOutputStream logic whereby an IO with an external encoding will always fail to write incoming bytes. We use base logic to detect if the target object is a "real IO" and if so and it has an external encoding, we drop the realIO and. This causes the rest of IOOutputStream to avoid the fast path and always use dyncall logic with RubyString wrappers. This works around the issue in jruby/jruby#8682. This should be temporary, since it will definitely degrade direct writes to such IO objects, but a longer-term fix for the encoding issues spelled out in jruby/jruby#8682 will need to come first, or else json will have to be modified to not use IOOutputStream at all.
Contributor
Author
|
The root issue this works around is technically jruby/jruby#6588 but this temporary fix will address the failing rdoc test from jruby/jruby#8682 and allow the test to be restored. |
3 tasks
Contributor
Author
|
#760 details the ongoing work needed after this workaround. |
Contributor
Author
|
@byroot @nobu When this is released, the rdoc test disabled for jruby/jruby#8682 can be restored by either getting a new JRuby out or by installing latest json gem. |
headius
added a commit
to headius/jruby
that referenced
this pull request
Mar 10, 2025
Logic in strTranscode evolved over the years to allow same-encoding requests to be no-ops. Those changes were never applied to rbByteEncode, resulting in same-encoding requests triggering errors when the transcoding subsystem saw nothing would be done. This complicated efforts to solve jruby#8682 by passing an encoding to the IOOutputStream constructor (ruby/json#759 and ruby/json#760). This patch allows using IOOutputStream and the byte[] IO API it calls with an externally-encoded IO by passing in an expected encoding for incoming bytes. All bytes will be treated as being encoded properly, and if the source and destination encoding is the same, rbByteEncode will return null to indicate no-op. Note that this misses some functionality of strTranscode in that it does not scrub the string for same-encoding requests. Partially addresses ruby/json#760. Fixes jruby#8686.
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.
This works around a bug in JRuby's IOOutputStream logic whereby an IO with an external encoding will always fail to write incoming bytes. We use base logic to detect if the target object is a "real IO" and if so and it has an external encoding, we drop the realIO and. This causes the rest of IOOutputStream to avoid the fast path and always use dyncall logic with RubyString wrappers.
This works around the issue in jruby/jruby#8682.
This should be temporary, since it will definitely degrade direct writes to such IO objects, but a longer-term fix for the encoding issues spelled out in jruby/jruby#8682 will need to come first, or else json will have to be modified to not use IOOutputStream at all.