Uploaded image for project: 'CouchDB'
  1. CouchDB
  2. COUCHDB-681

couch_util:encodeBase64 vs base64:encode

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • None
    • Infrastructure
    • trunk and all other branches

    Description

      Just noticed that OTP's base64:encode is about one order of magnitude faster than couch_util:encodeBase64:

      fdmanana@core2duo:~/git/couchdb/bin$ ./couchdb -i
      Erlang R13B03 (erts-5.7.4) [source] [64-bit] [smp:2:2] [rq:2] [async-threads:0] [hipe] [kernel-poll:true]

      Eshell V5.7.4 (abort with ^G)
      1> Apache CouchDB 0.11.0bd318717-git (LogLevel=info) is starting.
      Apache CouchDB has started. Time to relax.
      [info] [<0.37.0>] Apache CouchDB has started on http://127.0.0.1:5984/

      1> L = crypto:rand_bytes(1024 * 1024).
      <<10,238,241,237,52,176,52,252,99,133,199,63,177,68,141,
      24,225,251,115,187,34,143,152,253,150,170,9,122,0,...>>
      2>
      2> timer:tc(couch_util, encodeBase64, [L]).

      {368052, <<"Cu7x7TSwNPxjhcc/sUSNGOH7c7sij5j9lqoJegDoP07QyKeuCeMtWD7aXcW0junYH1csNda3F83owKQDw6D8pI+Ep0A231BD2sMEYF0XFkCW"...>>}

      3> timer:tc(couch_util, encodeBase64, [L]).

      {361919, <<"Cu7x7TSwNPxjhcc/sUSNGOH7c7sij5j9lqoJegDoP07QyKeuCeMtWD7aXcW0junYH1csNda3F83owKQDw6D8pI+Ep0A231BD2sMEYF0XFkCW"...>>}

      4> timer:tc(couch_util, encodeBase64, [L]).

      {361141, <<"Cu7x7TSwNPxjhcc/sUSNGOH7c7sij5j9lqoJegDoP07QyKeuCeMtWD7aXcW0junYH1csNda3F83owKQDw6D8pI+Ep0A231BD2sMEYF0XFkCW"...>>}

      5>
      5> timer:tc(base64, encode, [L]).

      {91055, <<"Cu7x7TSwNPxjhcc/sUSNGOH7c7sij5j9lqoJegDoP07QyKeuCeMtWD7aXcW0junYH1csNda3F83owKQDw6D8pI+Ep0A231BD2sMEYF0XFkCW"...>>}

      6> timer:tc(base64, encode, [L]).

      {107130, <<"Cu7x7TSwNPxjhcc/sUSNGOH7c7sij5j9lqoJegDoP07QyKeuCeMtWD7aXcW0junYH1csNda3F83owKQDw6D8pI+Ep0A231BD2sMEYF0XFkCW"...>>}

      7> timer:tc(base64, encode, [L]).

      {96070, <<"Cu7x7TSwNPxjhcc/sUSNGOH7c7sij5j9lqoJegDoP07QyKeuCeMtWD7aXcW0junYH1csNda3F83owKQDw6D8pI+Ep0A231BD2sMEYF0XFkCW"...>>}

      Same goes for base64:decode vs couch_util:decodeBase64

      Therefore I supply a patch to do the switch.
      It also allows us to short a little couch_util

      I executed all tests, both Etap and JS, and everything is fine with the switch.

      Attachments

        1. base64-trunk.patch
          7 kB
          Filipe David Borba Manana
        2. base64-trunk-2.patch
          9 kB
          Filipe David Borba Manana

        Activity

          People

            Unassigned Unassigned
            fdmanana Filipe David Borba Manana
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: