You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Today we have to serialize to a byte array before we can hash a PBJ protobuf object. This is wasteful in time and more importantly heap object garbage. For example we do:
Add an overloaded write(MessageDigest digest) method to Codec interface and generated implementations. It can call the normal write(T o, WritableSequentialData out) use a custom implementation of WritableSequentialData that wraps a java.security.MessageDigest mapping the write(byte) and write(byte[]) methods to update(byte) and update(byte[]) methods on MessageDigest. This will avoid the creation of temporary byte arrays and ByteArrayOutputStreams.
Alternatives
No response
The text was updated successfully, but these errors were encountered:
Probably fine, don't think there is a performance impact from first look other than extra object created. Adding the PBJ method would make code cleaner and give single point to performance test and improve over time. We know that PBJ serialization is expensive and if there is a more efficient way to hash a PBJ object in the future then that would be nice if there was only a couple APIs where we know it is done and they are used everywhere.
Problem
Today we have to serialize to a byte array before we can hash a PBJ protobuf object. This is wasteful in time and more importantly heap object garbage. For example we do:
EventCore.PROTOBUF.toBytes(event.getEventCore()).writeTo(eventDigest)
Solution
Add an overloaded
write(MessageDigest digest)
method to Codec interface and generated implementations. It can call the normalwrite(T o, WritableSequentialData out)
use a custom implementation ofWritableSequentialData
that wraps ajava.security.MessageDigest
mapping thewrite(byte)
andwrite(byte[])
methods toupdate(byte)
andupdate(byte[])
methods on MessageDigest. This will avoid the creation of temporary byte arrays and ByteArrayOutputStreams.Alternatives
No response
The text was updated successfully, but these errors were encountered: