vendredi 29 novembre 2019

Will method invocation reflection in Scala cause performance degradation?

I have a method intended to do some simple statistics for data IO, as shown below.

def ioStatSink[T <: { def length: Int }](): Sink[T, Future[(Long, Long)]] = Sink.fold((0L, 0L))((acc, bytes) => (acc._1 + 1L, acc._2 + bytes.length))

As I want it to be able to handle different data types that have a { def length: Int } method, I make it generic.
The problem is, this method invocation uses reflection.
As this method is called millions fo times, I don't want it to have performance issue.
I know class instantiation with reflection has performance penalty, but how about this method invocation?

(another issue about the method is, it cannot adapt to types with a method of { def length: Long }, any suggestion to deal with this?)





Aucun commentaire:

Enregistrer un commentaire