pjfanning commented on code in PR #3300:
URL: https://github.com/apache/pekko/pull/3300#discussion_r3535860165
##########
remote/src/main/scala/org/apache/pekko/remote/serialization/ProtobufSerializer.scala:
##########
@@ -101,21 +98,20 @@ class ProtobufSerializer(val system: ExtendedActorSystem)
extends BaseSerializer
override def toBinary(obj: AnyRef): Array[Byte] = {
val clazz = obj.getClass
- @tailrec
- def toByteArrayMethod(method: Method = null): Method = {
+ def toByteArrayMethod(): MethodHandle = {
val toByteArrayMethodBinding = toByteArrayMethodBindingRef.get()
toByteArrayMethodBinding.get(clazz) match {
- case Some(cachedtoByteArrayMethod) => cachedtoByteArrayMethod
- case None =>
- val unCachedtoByteArrayMethod =
- if (method eq null) clazz.getMethod("toByteArray")
- else method
+ case Some(cachedHandle) => cachedHandle
+ case None =>
+ val unCachedHandle = MethodHandles
+ .publicLookup()
+ .findVirtual(clazz, "toByteArray",
MethodType.methodType(classOf[Array[Byte]]))
Review Comment:
can we cache `MethodType.methodType(classOf[Array[Byte]])`?
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]