#7 Performance improvement for JSONUtils.quote

closed
nobody
None
5
2008-07-25
2008-07-17
Peter Schubert
No

I've done some profiling over JSON marshalling and unmarshalling and it seems they are quite slow.

I set out to improving the performance and I can present a small victory: the improvement of JSONUtils.quote().

Changes:
- reorganized the switch/case
- eliminated charAt() calls
- buffered chars for bulk appends (this brings the biggest improvement)
- replaced StringBuffer with StringBuilder

I don't know exactly how much faster it is, but let's just say that it went from the biggest hotspot to almost nothing.

I'm not sure what patching format is expected, I just zipped the source file. I guess you can figure it out yourself what the differences are.

Note: I used StringBuilder instead of StringBuffer, because I only use Java 6, but feel free to drop that change.

Discussion

  • Peter Schubert
    Peter Schubert
    2008-07-17

    actual source file

     
    Attachments
  • aalmiray
    aalmiray
    2008-07-17

    Logged In: YES
    user_id=1192026
    Originator: NO

    Thanks Peter, I'll review the code and apply the changes shortly.
    StringBuilder support may be available in the jdk5 version without a problem.

    In case you'd like to submit more pacthes in the future, we use cvs so a regular diff is enough =)

     
  • aalmiray
    aalmiray
    2008-07-19

    • status: open --> closed
     
  • aalmiray
    aalmiray
    2008-07-19

    Logged In: YES
    user_id=1192026
    Originator: NO

    FIXED.

     
  • Peter Schubert
    Peter Schubert
    2008-07-24

    • status: closed --> open
     
  • Peter Schubert
    Peter Schubert
    2008-07-24

    Logged In: YES
    user_id=1588362
    Originator: YES

    Sorry, I slipped in a bug: at line 501, it should be:

    sb.append( buffer, 0, bufferIndex );

     
  • aalmiray
    aalmiray
    2008-07-25

    Logged In: YES
    user_id=1192026
    Originator: NO

    Thanks, applied the fix.

     
  • aalmiray
    aalmiray
    2008-07-25

    • status: open --> closed