Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure_ascii=False could do with a C implementation #207

Open
richvdh opened this issue Mar 23, 2018 · 2 comments
Open

ensure_ascii=False could do with a C implementation #207

richvdh opened this issue Mar 23, 2018 · 2 comments

Comments

@richvdh
Copy link
Contributor

richvdh commented Mar 23, 2018

It's a real shame that there's no C implementation of encode_basestring - so the ensure_ascii=False codepath is so slow.

I don't really have enough context to fully understand it, but it looks to me like encode_basestring ought to be simpler to implement in C than py_encode_basestring_ascii, which of course already has a C implementation.

@etrepum
Copy link
Member

etrepum commented Mar 23, 2018

It shouldn't be more complicated, it just didn't get implemented because we weren't using that code path. If you'd like to try your hand at a PR I'd be happy to collaborate on it to get it merged.

@CaselIT
Copy link

CaselIT commented Dec 23, 2019

I came here to open an issue about it, but there was one already open.
The default implementation in python 3.7 does not have this problem (it is actually faster when set to False)

In [22]: %timeit s = simplejson.dumps(xj, ensure_ascii=False)
8.17 ms ± 279 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

In [23]: %timeit s = simplejson.dumps(xj, ensure_ascii=True)
3.43 ms ± 201 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

In [25]: %timeit s = json.dumps(xj, ensure_ascii=False)
3.19 ms ± 102 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

In [24]: %timeit s = json.dumps(xj, ensure_ascii=True)
3.42 ms ± 338 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

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

No branches or pull requests

3 participants