Search code examples
optaplanner

OptaPlanner how to get LambdaMetafactory access


I noticed this is OptaPlanner's logging output:

[TRACE] [2023-09-24 17:25:14,657] [main] [o.o.c.i.d.s.d.SolutionDescriptor]     Model annotations parsed for solution MySolution:
[TRACE] [2023-09-24 17:25:14,658] [main] [o.o.c.i.d.s.d.SolutionDescriptor]         Entity MyClass1:
[TRACE] [2023-09-24 17:25:14,658] [main] [o.o.c.i.d.s.d.SolutionDescriptor]             Genuine variable interval (pretty fast access with LambdaMetafactory)
[TRACE] [2023-09-24 17:25:14,658] [main] [o.o.c.i.d.s.d.SolutionDescriptor]         Entity MyClass2:
[TRACE] [2023-09-24 17:25:14,659] [main] [o.o.c.i.d.s.d.SolutionDescriptor]             Shadow variable events (slow access with reflection)

Why would one class get pretty fast access and the other get slow access? What are the requirements to get pretty fast access for a class?


Solution

  • In Timefold, the LambdaMetaFactory accessors no longer exists - it was causing a metaspace memory leak. Also, the reflection access is no longer called "slow" - it is the fastest accessor possible with the supported APIs of the JDK, and the difference from the metafactory approach was negligible in our benchmarks.