stevedlawrence commented on code in PR #1159:
URL: https://github.com/apache/daffodil/pull/1159#discussion_r1492712248
##########
daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/infoset/JsonInfosetOutputter.scala:
##########
@@ -29,12 +29,15 @@ import org.apache.daffodil.runtime1.api.InfosetSimpleElement
import com.fasterxml.jackson.core.io.JsonStringEncoder
-class JsonInfosetOutputter private (writer: java.io.Writer, pretty: Boolean)
+class JsonInfosetOutputter private (writer: java.io.BufferedWriter, pretty:
Boolean)
extends InfosetOutputter
with Indentable {
def this(os: java.io.OutputStream, pretty: Boolean) = {
- this(new java.io.OutputStreamWriter(os, StandardCharsets.UTF_8), pretty)
+ this(
+ new java.io.BufferedWriter(new java.io.OutputStreamWriter(os,
StandardCharsets.UTF_8)),
Review Comment:
> Add a comment here that this buffered writer provides significant
performance improvement.
WIll do.
> But we need a writer wrapped around the output stream anyway.
Correct. When I was looking at the profiler, every write required spinning
up a stream encoder, which has a lot of overhead. It's much more efficient to
encode a bunch of characters at once. So we need a `BufferedWriter` regardless
of what the `os` parameter is.
I just tested what happens if the `os` parameter is already a
`BufferedOutputStream` (i.e. essentially double buffering), and it doesn't make
a noticeable difference in parse time. So it's unnecessary to pass in a
`BufferedOutuptStream`, but it doesn't hurt.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]