check_circular=False when encoding JSON #1006

Closed
davidmarin opened this Issue Apr 28, 2015 · 6 comments

Comments

Projects
None yet
1 participant
@davidmarin
Collaborator

davidmarin commented Apr 28, 2015

We should be able to squeeze out a little extra efficiency by passing check_circular=False to json.dumps().

We should save this for when strict protocols are on by default; currently, a circular reference would just count as unencodable output (causing a counter to be incremented), whereas without the check, it would cause a stack overflow.

Should of course do some timing tests and see how much this matters.

@davidmarin davidmarin added the Feature label Apr 28, 2015

@davidmarin davidmarin added this to the v0.5.0 milestone Apr 28, 2015

@davidmarin

This comment has been minimized.

Show comment
Hide comment
@davidmarin

davidmarin Jun 1, 2015

Collaborator

Actually, if you try to encode a circular object with check_circular=False, you get a very clear RuntimeError (tried this with both json and simplejson).

Collaborator

davidmarin commented Jun 1, 2015

Actually, if you try to encode a circular object with check_circular=False, you get a very clear RuntimeError (tried this with both json and simplejson).

@davidmarin

This comment has been minimized.

Show comment
Hide comment
@davidmarin

davidmarin Jun 2, 2015

Collaborator

Huh, looks like check_circular=False can actually make things slower!

>>> timeit.timeit(stmt="json.dumps({'a': 1})",setup='import json')
8.669019937515259
>>> timeit.timeit(stmt="json.dumps({'a': 1}, check_circular=False)",setup='import json')
12.88784909248352

Maybe because it disables C speedups or something?

This is in Python 2.7.5.

Collaborator

davidmarin commented Jun 2, 2015

Huh, looks like check_circular=False can actually make things slower!

>>> timeit.timeit(stmt="json.dumps({'a': 1})",setup='import json')
8.669019937515259
>>> timeit.timeit(stmt="json.dumps({'a': 1}, check_circular=False)",setup='import json')
12.88784909248352

Maybe because it disables C speedups or something?

This is in Python 2.7.5.

@davidmarin

This comment has been minimized.

Show comment
Hide comment
@davidmarin

davidmarin Jun 2, 2015

Collaborator

Same in Python 3.4.1, except it takes 10.8 and 14.8 seconds, respectively.

Collaborator

davidmarin commented Jun 2, 2015

Same in Python 3.4.1, except it takes 10.8 and 14.8 seconds, respectively.

@davidmarin

This comment has been minimized.

Show comment
Hide comment
@davidmarin

davidmarin Jun 2, 2015

Collaborator

simplejson is actually slower in Python 3! (17.7 and 27.7)

Looks like simplejson is somewhat obselete, and we should actually be using ujson.

Collaborator

davidmarin commented Jun 2, 2015

simplejson is actually slower in Python 3! (17.7 and 27.7)

Looks like simplejson is somewhat obselete, and we should actually be using ujson.

@davidmarin

This comment has been minimized.

Show comment
Hide comment
@davidmarin

davidmarin Jun 2, 2015

Collaborator

This ticket is a bad idea, so closing it.

Collaborator

davidmarin commented Jun 2, 2015

This ticket is a bad idea, so closing it.

@davidmarin davidmarin closed this Jun 2, 2015

@davidmarin davidmarin removed the Feature label Jun 2, 2015

@davidmarin davidmarin removed this from the v0.5.0 milestone Jun 2, 2015

@davidmarin

This comment has been minimized.

Show comment
Hide comment
@davidmarin

davidmarin Jun 2, 2015

Collaborator

For comparison, in Python 3.4.1:

>>> timeit.timeit(stmt="json.dumps({'a': 1})",setup='import ujson as json')
1.235375051968731
Collaborator

davidmarin commented Jun 2, 2015

For comparison, in Python 3.4.1:

>>> timeit.timeit(stmt="json.dumps({'a': 1})",setup='import ujson as json')
1.235375051968731
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment