-
Notifications
You must be signed in to change notification settings - Fork 18
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
use ByteStringInputStream #309
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm
runtime/src/main/scala/org/apache/pekko/grpc/internal/ByteStringInputStream.scala
Outdated
Show resolved
Hide resolved
Co-Authored-By: João Ferreira <[email protected]>
def apply(bs: ByteString): InputStream = bs match { | ||
case cs: ByteString1C => | ||
getInputStreamUnsafe(cs) | ||
case _ => | ||
if (byteStringInputStreamMethodTypeOpt.isDefined) { | ||
byteStringInputStreamMethodTypeOpt.get.invoke(bs).asInstanceOf[InputStream] | ||
} else { | ||
legacyConvert(bs) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and what about:
def apply(bs: ByteString): InputStream = bs match { | |
case cs: ByteString1C => | |
getInputStreamUnsafe(cs) | |
case _ => | |
if (byteStringInputStreamMethodTypeOpt.isDefined) { | |
byteStringInputStreamMethodTypeOpt.get.invoke(bs).asInstanceOf[InputStream] | |
} else { | |
legacyConvert(bs) | |
} | |
} | |
def apply(bs: ByteString): InputStream = { | |
if (byteStringInputStreamMethodTypeOpt.isDefined) { | |
byteStringInputStreamMethodTypeOpt.get.invoke(bs).asInstanceOf[InputStream] | |
} else { | |
legacyConvert(bs) | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another improvement could be the use of null
instead of None
in byteStringInputStreamMethodTypeOpt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll check it again but when I was benchmarking the changes before - having the ByteString1C case seemed to help performance. I can't track down the benchmarks that I used, I may need to write them again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually - the benchmark code that I used a few weeks ago is at https://github.com/pjfanning/pekko-test/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With your optimised version of legacyConvert, we may not need the MethodHandle. That code is basically what adInputStream does anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked in the simpler version. It seems good enough and Pekko 1.0 users benefit with this version.
Co-Authored-By: João Ferreira <[email protected]>
@He-Pin I reworked the code. Are you still happy with this change? |
@jtjeferreira It isn't strictly necessary but could you consider supplying an iCLA (if you haven't done so already)? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, checked the new SequenceInputStream
lgtm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
follow up to #308