-
Notifications
You must be signed in to change notification settings - Fork 333
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
JSON.dump: write directly into the provided IO #686
Conversation
Java side is implemented atop this PR in #538. |
We need some benchmarks! |
Ref: ruby#524 Rather than to buffer everything in memory. Unfortunately Ruby doesn't provide an API to write into and IO without first allocating a string, which is a bit wasteful.
When an IO is given, we should try to write directly to it. This patch moves that direction by always doing JSON dumping into an OutputStream, which can be implemented on top of a given IO or by producing a ByteList via a ByteArrayOutputStream.
This connects up the OutputStream-based generator logic to the incoming IO parameter (an IO or nil). Also included here are some small changes to support the new state.rb: * Require the state.rb file at the end of ext init. * Move State#configure to _configure. * Add State#strict? as an alias for strict.
I cherry picked you commits. Now TruffleRuby head seem to crash for some reason, but I'm having trouble understanding Truffle crash reports, so I'm going to assume it's just a bug in Truffle. FYI: @eregon Also the |
Re the TruffleRuby crash, @andrykonchin can you look at that? |
@byroot Thanks! I have some optimizations I'll do in a separate PR now. |
@eregon The issue is fixed in oracle/truffleruby@567aa27. |
Urk, I didn't realize |
Yes, I've never seen |
Ref: #524
Fix: #538
Fix: #524
Rather than to buffer everything in memory.
Unfortunately Ruby doesn't provide an API to write into and IO without first allocating a string, which is a bit wasteful.
FYI: @headius