Skip to content

Avoid Kotlin reflection for non-delegate properties - #3568

Open
gregjotau wants to merge 1 commit into
spring-projects:mainfrom
beint-no:kotlin-filter-short-circuit
Open

gregjotau wants to merge 1 commit into
spring-projects:mainfrom
beint-no:kotlin-filter-short-circuit

Conversation

@gregjotau

@gregjotau gregjotau commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Ordinary fields and properties currently trigger KotlinReflectionUtils.isDataClass even though their names cannot match the delegate-field pattern. Reject names without a $delegate suffix before inspecting Kotlin metadata. Candidate delegate names still pass through the existing data-class and regex checks, preserving their matching behavior.

Includes regression tests for both overloads and a JMH cold-start benchmark using the existing SimpleDataClass fixture. On upstream main 677c139, JDK 27 and the default Kotlin 2.4.21, ten fresh JVM forks with SingleShotTime, no warmup and -prof gc gave:

Filtering the fixture's two ordinary fields Main Patched
Mean ± JMH error 170.576 ± 20.560 ms 1.940 ± 0.424 ms
Allocation 22,011,113 B/op 590,817 B/op

This measures the filter's first use, including reflection initialization it triggers. Other application components can initialize the same metadata, so these figures are not a whole-application speedup claim. A separate Kotlin 2.5.0-Beta2 reproduction also improves with cold and cached metadata.

Validation: ./mvnw test passes (3,899 tests, zero failures/errors, 13 skipped). Eight fresh extracted Spring Boot application startups pass health, login-render and public API document checks. A separate instrumented startup recorded 4,019 calls to isDataClass from the filter across 328 declaring classes before the change and zero afterwards. Shared-host load prevents a reliable end-to-end timing claim. ./mvnw -Pjmh -DskipTests test-compile also passes.

Closes #3567.

Reject ordinary field and property names with a suffix check before inspecting Kotlin data-class metadata. Preserve the existing regex match for candidate delegate names and cover both paths with regression tests and a cold-fork benchmark.

Closes spring-projects#3567

Signed-off-by: Greg Taube <gregjotau@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 23, 2026
@gregjotau

Copy link
Copy Markdown
Contributor Author

@mp911de would be great to have this one for 4.2.0 spring boot :) We are already using the RC1 spring boot and benefit from the recently added performance improvements 🚀

FYI. this is just me asking gpt-6.1 sol:

can we deeply benchmark startup performance of reai app
Profile deeply and see if there is anything we can do in our own code to make it faster.
And check also if there is anything we can contribute upstream to make it faster

And then after the analysis:

Try to find at least one more worthwhile contribution.
But don't open it if you are not confident it is clearly an improvement/better

That was literally my prompt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid Kotlin metadata inspection for ordinary property names

2 participants