Avoid slow Class.forName when serializing lambdas by theigl · Pull Request #944 · EsotericSoftware/kryo (original) (raw)
This PR improves the performance of ClosureSerializer by avoiding calls to Class.forName whenever possible.
The change requires a reflective call to a private field in SerializedLambda, but since we already reflect into this class to get access to the readResolve method, I don't think this is an issue.
The new implementation is 2.5-3x faster:
| Benchmark | Mode | Cnt | Score | Error | Units |
|---|---|---|---|---|---|
| ClosureSerializerBenchmark.new | thrpt | 3 | 2816003 | ± 1112830,503 | ops/s |
| ClosureSerializerBenchmark.old | thrpt | 3 | 1134271 | ± 61452,742 | ops/s |