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

Specialize the TBinaryProtocol read path up to ~2x speedups #221

Merged
merged 2 commits into from
Jun 3, 2015

Conversation

ianoc
Copy link
Collaborator

@ianoc ianoc commented Jun 3, 2015

bijectiondeserwin

Can see the prior delta in the posted image. The macro stays below but the others that do full deserialization converge with this change.

}

override def apply(item: T) = thriftStructSerializer.toBytes(item)
override def invert(bytes: Array[Byte]) = attempt(bytes){ bytes =>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about Macros.fastAttempt here to avoid the closure. :) Maybe no win, but it can't hurt.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perf sensitive code, might as well take every little bit.

@mosesn
Copy link
Contributor

mosesn commented Jun 3, 2015

This isn't feasible for dependency reasons, but it would be nice if we didn't duplicate work. We have an implementation of TBinaryProtocol in finagle to minimize allocations:

https://github.com/twitter/finagle/blob/master/finagle-thrift/src/main/scala/com/twitter/finagle/thrift/Protocols.scala#L51

It would be neat to be able to use your optimizations when possible too.

@ianoc
Copy link
Collaborator Author

ianoc commented Jun 3, 2015

Yeah alas not obvious for that, a scrooge-thrift type package with slim deps might be a good middle ground to use for everything

@johnynek
Copy link
Collaborator

johnynek commented Jun 3, 2015

looks good. Nice work.

johnynek added a commit that referenced this pull request Jun 3, 2015
Specialize the TBinaryProtocol read path up to ~2x speedups
@johnynek johnynek merged commit 846253c into develop Jun 3, 2015
@johnynek johnynek deleted the specializeTBinaryProtocolReading branch June 3, 2015 19:35
def readString: String =
try {
val size = readI32
val s = new String(transport.buf, transport.bufferPos, size, "UTF-8")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't mention any relative performance numbers, much faster?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is the one that I'm thinking of, up to 40x faster, but it only applies to java6 and was fixed in java7. But I could be wrong.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well we are moving to java8, so not sure it matters much if fixed in java7

On Thu, Jun 18, 2015 at 11:32 AM, Alex Levenson notifications@github.com
wrote:

In
bijection-thrift/src/main/scala/com/twitter/bijection/thrift/TArrayBinaryProtocol.scala
#221 (comment):

  •  ((transport.buf(off + 1) & 0xffL) << 48) |
    
  •  ((transport.buf(off + 2) & 0xffL) << 40) |
    
  •  ((transport.buf(off + 3) & 0xffL) << 32) |
    
  •  ((transport.buf(off + 4) & 0xffL) << 24) |
    
  •  ((transport.buf(off + 5) & 0xffL) << 16) |
    
  •  ((transport.buf(off + 6) & 0xffL) << 8) |
    
  •  ((transport.buf(off + 7) & 0xffL))
    
  • }
  • def readDouble: Double =
  • java.lang.Double.longBitsToDouble(readI64)
  • def readString: String =
  • try {
  •  val size = readI32
    
  •  val s = new String(transport.buf, transport.bufferPos, size, "UTF-8")
    

If this is the one that I'm thinking of, up to 40x faster, but it only
applies to java6 and was fixed in java7. But I could be wrong.


Reply to this email directly or view it on GitHub
https://github.com/twitter/bijection/pull/221/files#r32762644.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't really tell, a read a blog post just now that said they fixed it for single-byte charsets, but not yet for multi-byte charsets like utf8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants