Skip to content

Commit

Permalink
Optimization: inline the header check in ProtoEncoder (#25)
Browse files Browse the repository at this point in the history
This should slightly boost perf, especially on JVMs with less aggressive
JIT inlining.
  • Loading branch information
Ostrzyciel authored Sep 12, 2023
1 parent fe9f6e8 commit abca7ae
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions core/src/main/scala/eu/ostrzyciel/jelly/core/ProtoEncoder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ abstract class ProtoEncoder[TNode, TTriple, TQuad, TQuoted](val options: RdfStre
* @return iterable of stream rows (always of length 1)
*/
final def endGraph(): Iterable[RdfStreamRow] =
if !emittedCompressionOptions then
if !emittedOptions then
throw new RdfProtoSerializationError("Cannot end a delimited graph before starting one")
ProtoEncoder.graphEnd

Expand Down Expand Up @@ -181,7 +181,7 @@ abstract class ProtoEncoder[TNode, TTriple, TQuad, TQuoted](val options: RdfStre
// *************************************
private var extraRowsBuffer = new ListBuffer[RdfStreamRow]()
private val iriEncoder = new NameEncoder(options)
private var emittedCompressionOptions = false
private var emittedOptions = false

private val lastSubject: LastNodeHolder[TNode] = new LastNodeHolder()
private val lastPredicate: LastNodeHolder[TNode] = new LastNodeHolder()
Expand Down Expand Up @@ -231,12 +231,14 @@ abstract class ProtoEncoder[TNode, TTriple, TQuad, TQuoted](val options: RdfStre
o = nodeToProto(getQuotedO(quoted)),
)

private def handleHeader(): Unit =
private inline def handleHeader(): Unit =
extraRowsBuffer = new ListBuffer[RdfStreamRow]()
if !emittedCompressionOptions then
emittedCompressionOptions = true
extraRowsBuffer.append(
RdfStreamRow(RdfStreamRow.Row.Options(options))
)
if !emittedOptions then emitOptions()

private def emitOptions(): Unit =
emittedOptions = true
extraRowsBuffer.append(
RdfStreamRow(RdfStreamRow.Row.Options(options))
)


0 comments on commit abca7ae

Please sign in to comment.