Gendrop / webapp-improved

Automatically exported from code.google.com/p/webapp-improved
Other
0 stars 0 forks source link

json.dump(data, self.response) is incredibly slow #94

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Using the webapp2.Response object as a writer for json.dump appears to hit 
quadratic string concatenation complexity and is extremely slow.

Test case app:

import json
import time
import webapp2
class Test(webapp2.RequestHandler):
  def get(self):
    data = ['test'] * int(1e6)
    start = time.time()
    if self.request.get('method') == 'dumps':
        self.response.write(json.dumps(data))
    else:
        json.dump(data, self.response)
    print 'Time taken: %ss' % (time.time() - start)
application = webapp2.WSGIApplication([
    ('/test', Test),
], debug=True)

Stdout for http://localhost:8080/test?method=dump:
Time taken: 7.93935012817s

Stdout for http://localhost:8080/test?method=dumps:
Time taken: 0.123687982559s

Original issue reported on code.google.com by alancut...@chromium.org on 24 Sep 2014 at 4:20