One explaination I came up was that Java is performing a full upcast when encountering the generic-based interface. Unchecked and checked genetics perform identically.
Because the generics are fully removed at compile time; Java may be forced to do full type casting every time the method is called. If there isn’t something inherently wrong with the test then there is a big performance penalty when using generic interfaces. On Thu, Oct 11, 2018 at 12:50 PM Emmanuel Lécharny <[email protected]> wrote: > Thanks, Jonathan, > > Le 11/10/2018 à 18:07, Jonathan Valliere a écrit : > > I was having a conversation with a colleague last week about the cost of > > automatic casting due to the use of generics in java; so, I decided to > > write a benchmark. Since everyone wants their networking code to run as > > fast as possible, I thought I would share it with all of you. > > > > Feel free to peer-review the code. > > https://github.com/jon-valliere/jmh-generics-benchmark > > Running this benchmark, I get a 10x slower run when using generic > compared to the non-generic version (3G op/s vs 300M op/s) > > That beaing said, Generic are't supposed to have any impact on java > code, because it's all removed by the compiler, so there must be > something weirdo going on. It would be interesting to check the > generated bytecode to see the difference. > > > -- > Emmanuel Lecharny > > Symas.com > directory.apache.org > >
