Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

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

Open
GoogleCodeExporter opened this issue Feb 26, 2016 · 0 comments
Open

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

GoogleCodeExporter opened this issue Feb 26, 2016 · 0 comments

Comments

@GoogleCodeExporter
Copy link

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 [email protected] on 24 Sep 2014 at 4:20

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant