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

json: slow as hell #3809

Closed
scriptum opened this issue Feb 1, 2016 · 10 comments · Fixed by #3810
Closed

json: slow as hell #3809

scriptum opened this issue Feb 1, 2016 · 10 comments · Fixed by #3810

Comments

@scriptum
Copy link
Contributor

scriptum commented Feb 1, 2016

I have a very BIG issue with loading ~2 MB json data. It looks like parsing time grows exponentially while increasing data size.
Here is python sample:

import json
d = {}
for i in range(1, 200000):
  d[str(i)] = i
json.loads(json.dumps(d)) # 0.55 sec

Now guess Nim's time:

import json
let jobj = newJObject()
for i in 1..<200000:
  jobj.add($i, newJInt(i))
let jobj_parsed = parseJSon($jobj)
@refi64
Copy link
Contributor

refi64 commented Feb 1, 2016

"Now guess Nim's time" leads back to this page. Does it take 3809 seconds or something?

@scriptum
Copy link
Contributor Author

scriptum commented Feb 1, 2016

This is a hover-spoiler 😄

@Araq
Copy link
Member

Araq commented Feb 1, 2016

Give us the test-json somehow.

@def-
Copy link
Member

def- commented Feb 1, 2016

@Araq It's created by the test program.

@scriptum
Copy link
Contributor Author

scriptum commented Feb 1, 2016

@Araq this is simplified test that exactly reproduces my case. I have a many key-value pairs in json format, approximately 2 Megabytes.

You may also try this as test input:
(echo "{"; sed 's/.*/"&":null,/' /usr/share/dict/words; echo "}") > test.json

@refi64
Copy link
Contributor

refi64 commented Feb 1, 2016

I had to download another web browser just to see it (on Android ATM).

@scriptum
Copy link
Contributor Author

scriptum commented Feb 1, 2016

@kirbyfan64 I'm sorry this was simplest way to create spoiler on GitHub

@def-
Copy link
Member

def- commented Feb 1, 2016

The problem is that a JObject's fields are a seq of key, val pairs. When you want to insert a new key it is checked for equivalence to each existing key. If I remove that one check it finishes in 0.2 seconds on my computer. I'll try to use a Table instead.

@scriptum
Copy link
Contributor Author

scriptum commented Feb 1, 2016

@def- 0.2 - sounds good!

def- added a commit to def-/Nim that referenced this issue Feb 1, 2016
Significant speedup for some operations, fixes nim-lang#3809
Not tested very well yet
@def-
Copy link
Member

def- commented Feb 1, 2016

@scriptum Take a look at #3810 please, faster than python for me.

def- added a commit to def-/Nim that referenced this issue Feb 7, 2016
Significant speedup for some operations, fixes nim-lang#3809
Not tested very well yet
def- added a commit to def-/Nim that referenced this issue Feb 24, 2016
Significant speedup for some operations, fixes nim-lang#3809
Not tested very well yet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants