Skip to content

perf: optimize AbstractParameterProcessor.readParameters - #2646

Merged
MikeEdgar merged 1 commit into
smallrye:mainfrom
Postremus:issues/2630-perf-optimize-readParameters
Aug 31, 2026
Merged

perf: optimize AbstractParameterProcessor.readParameters#2646
MikeEdgar merged 1 commit into
smallrye:mainfrom
Postremus:issues/2630-perf-optimize-readParameters

Conversation

@Postremus

Copy link
Copy Markdown
Contributor

readParameters checked each annotation on the class, if it is parameter. Then checked if the annotation instances target is FIELD|METHOD|METHOD_PARAMETER, and then checked that target if it has any parameter annotations. I turned it around. We overall only check fields and methods now for parameter annotations. For fields we only require one isParameter check for the specific annotation instance. For methods, we check if the method could even be a bean property method first. Short circuit for parameterless methods (constructors, static initializers). This saves around 2/3 of the calls towards isResourceMethod (150k -> 50k). We also save on retrieving the annotations of each target again and again, if the target has multiple parameter annotations (resource methods, constructors).

Optimize JaxRsParameterProcessor.hasMethodHTTPMethodAnnotation further to save on the ArrayList allocation inside MethodInfo.declaredAnnotations(). Also compare by name directly instead of AnnotationInstance.

sorted-parameters.enable=false had the problem, that parameters picked up from beanparams where not sorted in declaration order. They where instead grouped by annotation (i.e. path param, query param, etc), and in each group in declaration order. The behaviour is now so that beanparams also follow declaration order; And their parameters are inserted right between the other parameters from the "parents" (e.g. the resource methods) parameters. This is also ensured for parameters declared on constructors. Jandex sorts method parameters alphabetically, so we have to resort based on parameter position.

Add a test to ensure the declaration order sorting stays consistent.

Saves about 80ms of quarkus:build.

related to #2630
replaces #2645

readParameters checked each annotation on the class, if it is parameter. Then checked if the annotation instances target is FIELD|METHOD|METHOD_PARAMETER, and then checked that target if it has any parameter annotations.
I turned it around. We overall only check fields and methods now for parameter annotations. For fields we only require one isParameter check for the specific annotation instance. For methods, we check if the method could even be a bean property method first. Short circuit for parameterless methods (constructors, static initializers). This saves around 2/3 of the calls towards isResourceMethod (150k -> 50k). We also save on retrieving the annotations of each target again and again, if the target has multiple parameter annotations (resource methods, constructors).

Optimize JaxRsParameterProcessor.hasMethodHTTPMethodAnnotation further to save on the ArrayList allocation inside MethodInfo.declaredAnnotations(). Also compare by name directly instead of AnnotationInstance.

sorted-parameters.enable=false had the problem, that parameters picked up from beanparams where not sorted in declaration order.
They where instead grouped by annotation (i.e. path param, query param, etc), and in each group in declaration order.
The behaviour is now so that beanparams also follow declaration order; And their parameters are inserted right between the other parameters from the "parents" (e.g. the resource methods) parameters.
This is also ensured for parameters declared on constructors. Jandex sorts method parameters alphabetically, so we have to resort based on parameter position.

Add a test to ensure the declaration order sorting stays consistent.
@sonarqubecloud

Copy link
Copy Markdown

@Postremus Postremus changed the title per: optimize AbstractParameterProcessor.readParameters perf: optimize AbstractParameterProcessor.readParameters Aug 31, 2026
@MikeEdgar MikeEdgar added this to the 4.4.0 milestone Aug 31, 2026

@MikeEdgar MikeEdgar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, thanks @Postremus !

@MikeEdgar

Copy link
Copy Markdown
Member

@Postremus I'll go ahead and merge this unless you're still working on more changes.

@Postremus

Copy link
Copy Markdown
Contributor Author

@MikeEdgar
No thats it for now.

Thank you.

@MikeEdgar
MikeEdgar merged commit a688a69 into smallrye:main Aug 31, 2026
20 checks passed
@Postremus
Postremus deleted the issues/2630-perf-optimize-readParameters branch August 31, 2026 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants