Repository navigation
Conversation
|
Do you have any insights into whether this is faster? We cache the In general I like the idea - testing it is of course problematic - but it might be worth having even without a specific test in the code base. |
|
Method access seems to be a little bit faster (and with less variance, so a more constant performance profile): This probably has to do something with the fact that record fields are compiled to private fields, and thus access checks take more time (even when setAccessible is set). Benchmarks: https://github.com/jord1e/graphql-java/pull/2/files The JEP also makes clear that the default generated 'getters' (e.g.
In the current situation possible side-effects (e.g. logging) will not be called for methods overriding generated record getters, whilst they will be recorded when the record manually has a I think this is a good change |
|
Compilers can also add custom behaviour, the Kotlin compiler adds non-null checks and @NotNull annotations to A custom data fetcher implementation may hypothetically check for the presence of these annotations. |
|
Thanks a lot @jord1e , but we decided not to adopt it. If you look at the JMH output and take the error range into considerations it is not clear that this faster. Additionally we are concerned with the introduction of JVM version specific code. I know you have another PR open which might help us to get there in the future, but would need to make sure that we test against Java 8 (at a minimum) and 16 with every build. This is a big step up in terms of maintenance and commitment for us, which only want to take if really needed. Thanks a lot! |


See title.
Records were introduced in JDK 16 by JEP 395. When the field (constructor parameter) is called
a, the method will be calleda()- even when it is a boolean.I tested it manually. Adding a JDK 16+ testing target will be a little bit harder.
Migrating to Gradle JVM Test Suites might help in the future.
Kotlin can also compile
data classes to records by adding a special@JvmRecordannotation: https://kotlinlang.org/docs/jvm-records.html#declare-records-in-kotlin=