Commit 3a2ad8e6 by imdark Committed by GitHub

in order to solve the memory leak at #5146

Large encoded string take a very long time to to release from memory, but if we just pass the stream directly into json.load we get much better memory performance.
parent 1ca5a9d0
......@@ -22,6 +22,7 @@ from django.utils.six.moves.urllib import parse as urlparse
from rest_framework import renderers
from rest_framework.exceptions import ParseError
import codecs
class DataAndFiles(object):
......@@ -61,8 +62,8 @@ class JSONParser(BaseParser):
encoding = parser_context.get('encoding', settings.DEFAULT_CHARSET)
try:
data = stream.read().decode(encoding)
return json.loads(data)
decoded_stream = codecs.decode(stream, encoding)
return json.load(decoded_stream)
except ValueError as exc:
raise ParseError('JSON parse error - %s' % six.text_type(exc))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment