[
https://issues.apache.org/jira/browse/CXF-7716?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16445411#comment-16445411
]
ASF GitHub Bot commented on CXF-7716:
-------------------------------------
asoldano commented on a change in pull request #407: [CXF-7716] Reduce
StringBuilders and other performance changes.
URL: https://github.com/apache/cxf/pull/407#discussion_r182964151
##########
File path:
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
##########
@@ -130,10 +130,31 @@ public String getPatternValue() {
private static String escapeCharacters(String expression) {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < expression.length(); i++) {
- char ch = expression.charAt(i);
- sb.append(isReservedCharacter(ch) ? "\\" + ch : ch);
+ int length = expression.length();
Review comment:
This being micro-optimization or not should really be supported by benchmark
result data. If this is on a hot path, creating less StringBuilder can really
make some differences.
This said, please note that the fix actually solves 2 issue:
1) it avoids creating the StringBuilder when not needed
2) it prevents useless StringBuilder instances being created whenever a
reserved character is found, as sb.append(isReservedCharacter(ch) ? "\\" + ch :
ch) internally creates another StringBuilder to perform the "\\" + ch
concatenation.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> IBM Performance Team has found several performance increases
> ------------------------------------------------------------
>
> Key: CXF-7716
> URL: https://issues.apache.org/jira/browse/CXF-7716
> Project: CXF
> Issue Type: Bug
> Components: JAX-RS
> Affects Versions: 3.0.15, 3.2.4
> Reporter: Adam Anderson
> Priority: Major
> Fix For: 3.2.5
>
> Original Estimate: 1h
> Remaining Estimate: 1h
>
> Our performance team has identified several areas of improvement to reduce
> garbage collection and CPU usage.
> First, we reduced the amount of StringBuilders created in HTTPUtils.java and
> ResourceUtils.java.
> Second, we created JAXRSUtils.doMimeTypesIntersect() - a method similar to
> JAXRSUtils.intersectMimeTypes - that doesn't create a HashSet but instead
> returns a boolean when we just need to know if they intersect.
> Third, we found that getting the annotations for parameters to create
> constructor arguments in PerRequestResourceProvider.java is expensive, so we
> cache them in the constructor instead of getting them via reflection every
> request.
> These changes combined result in a ~1.5-2% performance increase.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)