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

RubyIO needs allocation-free read and write paths #6589

Closed
headius opened this issue Mar 1, 2021 · 1 comment
Closed

RubyIO needs allocation-free read and write paths #6589

headius opened this issue Mar 1, 2021 · 1 comment

Comments

@headius
Copy link
Member

headius commented Mar 1, 2021

Currently there is no way to read from or write to a RubyIO without creating a RubyString and accompanying ByteList. Meanwhile we have many places where we want to write a ByteList or even just a byte[] with a given encoding, such as IOOutputStream or the copy_stream logic for non-files.

We should build and use read and write paths that accept at least ByteList and ideally byte[], start, length, encoding to avoid allocation altogether.

This might be a good beginner to intermediate task for an external contributor.

@headius
Copy link
Member Author

headius commented Mar 2, 2021

After attempting this myself, I'd say this is more of an advanced item... even for skilled Java folks.

PR coming.

@headius headius removed the beginner label Mar 2, 2021
headius added a commit to headius/jruby that referenced this issue Mar 2, 2021
Several Java-based consumers of RubyIO write to it without having
a RubyString in hand, by wrapping incoming byte[] or ByteList.
This patch adds a write path that can accept unwrapped byte[] plus
encoding to reduce allocation and follow a fast path.

Users that hit this logic, mostly via IOOutputStream:

* The Psych ext when dumping to an IO
* For stdout and stderr streams provided by Ruby.getError/OutputStream
* By Marshal for dumping to a target IO or IO-like
* By GzipWriter for writing to a stream
* Anyone that calls to_outputstream on an IO

Part of work for jruby#6589
@headius headius added this to the JRuby 9.3.0.0 milestone Mar 2, 2021
@headius headius closed this as completed Mar 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant