cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andy McCright (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CXF-7075) Remove unnecessary string.length() and map.containsKey(...) calls to improve performance
Date Wed, 05 Oct 2016 21:00:24 GMT

    [ https://issues.apache.org/jira/browse/CXF-7075?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15549928#comment-15549928
] 

Andy McCright commented on CXF-7075:
------------------------------------

Interestingly, when I bump up the TIMES_TO_RUN from 500k to 1 million, then the proposed fix
looks a bit slower:
Original Code Test
Time to parse one type: 146873609 nanoseconds
Time to parse two types: 119980999 nanoseconds
Time to parse three types: 158751189 nanoseconds
Time to parse twelve types: 792077205 nanoseconds
Proposed Change Test
Time to parse one type: 166478348 nanoseconds
Time to parse two types: 135731365 nanoseconds
Time to parse three types: 163320358 nanoseconds
Time to parse twelve types: 758674187 nanoseconds
Original Code Test
Time to parse one type: 157246321 nanoseconds
Time to parse two types: 129763922 nanoseconds
Time to parse three types: 164354449 nanoseconds
Time to parse twelve types: 840647904 nanoseconds
Proposed Change Test
Time to parse one type: 162607531 nanoseconds
Time to parse two types: 123097493 nanoseconds
Time to parse three types: 165173994 nanoseconds
Time to parse twelve types: 768583383 nanoseconds
Original Code Test
Time to parse one type: 143968053 nanoseconds
Time to parse two types: 133924033 nanoseconds
Time to parse three types: 161509309 nanoseconds
Time to parse twelve types: 809422872 nanoseconds
Proposed Change Test
Time to parse one type: 157101703 nanoseconds
Time to parse two types: 135634786 nanoseconds
Time to parse three types: 158294707 nanoseconds
Time to parse twelve types: 781427304 nanoseconds

I tried re-implementing another way which looks like it might be a little faster...
    public static List<MediaType> parseMediaTypes(String types) {
        List<MediaType> acceptValues = new ArrayList<MediaType>();
        
        if (types != null) {
            int x = 0;
            int y = types.indexOf(',');
            while (y > 0) {
                acceptValues.add(toMediaType(types.substring(x, y)));
                x = y + 2;
                y = types.indexOf(',', x);
            }
            acceptValues.add(toMediaType(types.substring(x)));

        } else {
            acceptValues.add(ALL_TYPES);
        }
        
        return acceptValues;
    }

With that code, I get these results (new code is labeled as Proposed):
Original Code Test
Time to parse one type: 162089550 nanoseconds
Time to parse two types: 121634212 nanoseconds
Time to parse three types: 164150901 nanoseconds
Time to parse twelve types: 1027082012 nanoseconds
Proposed Change Test
Time to parse one type: 147992281 nanoseconds
Time to parse two types: 118361681 nanoseconds
Time to parse three types: 154465943 nanoseconds
Time to parse twelve types: 744372633 nanoseconds
Original Code Test
Time to parse one type: 171457432 nanoseconds
Time to parse two types: 123348169 nanoseconds
Time to parse three types: 163685283 nanoseconds
Time to parse twelve types: 759016041 nanoseconds
Proposed Change Test
Time to parse one type: 147617428 nanoseconds
Time to parse two types: 118008933 nanoseconds
Time to parse three types: 153649110 nanoseconds
Time to parse twelve types: 756229153 nanoseconds
Original Code Test
Time to parse one type: 151245814 nanoseconds
Time to parse two types: 122917357 nanoseconds
Time to parse three types: 159188030 nanoseconds
Time to parse twelve types: 843513510 nanoseconds
Proposed Change Test
Time to parse one type: 145248903 nanoseconds
Time to parse two types: 118914505 nanoseconds
Time to parse three types: 155509909 nanoseconds
Time to parse twelve types: 767379270 nanoseconds

I haven't run this change on the simple JAX-RS benchmark, but I can do that -- I'll be on
vacation the next couple of days, so I may not have results until next week.

Thanks, Andy



> Remove unnecessary string.length() and map.containsKey(...) calls to improve performance
> ----------------------------------------------------------------------------------------
>
>                 Key: CXF-7075
>                 URL: https://issues.apache.org/jira/browse/CXF-7075
>             Project: CXF
>          Issue Type: Improvement
>          Components: JAX-RS
>    Affects Versions: 3.1.7
>            Reporter: Andy McCright
>         Attachments: JAXRSUtils-parseMediaType-perfTest.zip
>
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> Using a simple (echo) JAX-RS benchmark, we've found a few hot spots around string.length()
and map.containsKey(...) calls that could be optimized.  Initial testing with the proposed
changes yielded about a 2-3% improvement.  



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message