Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4098174

URLEncoder.encode is too slow

XMLWordPrintable

    • kestrel
    • sparc
    • solaris_2.5.1



      Name: gvC48267 Date: 12/09/97


      We profiled java.net.URLEncoder.encode() with the following URL:
      "http://bfc9002:40000/not/real/so/do-not/be/fooled/gadamer/atg-design/prototype-
      guidelines/index.html"

      It takes 22807 instructions and 70 allocations to encode this URL.
      30% of the instructions occur in java.io.ByteArrayOutputStream.toString().

      We later saw that BitSet.get()/set() are used in this process and are
      synchronized when they don't necessarily have to be. We wrote a test with our
      own non-synchronized method calls and got the following performance numbers.

      We called BitSet.get() 2048000 times and got these results:
      Synchronized: 26124 ms
      Unsynchronized: 6594 ms

      So synchronization makes BitSet.get() take 4 times as long.

      The standard implementation of URLEncoder.encode()
      makes N calls to BitSet.get(), where N is the length of the
      input string.

      Using my version of java.util.BitSet without synchronized get() and set()
      methods, I compared the overall performance of URLEncoder.encode()
      to its performance using the standard BitSet.

      I called URLEncoder.encode() 4000 times on a 100-character URL
      and got these results:

      Synchronized: 24632 ms
      Unsynchronized: 21708 ms

      So synchronization makes URLEncoder.encode() take about 13% longer.
      (Review ID: 21620)
      ======================================================================

            gellisonsunw Gary Ellison (Inactive)
            gvanassesunw Gunter Vanasse (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: