Skip to content

Convert json Reader to iterators #7704

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

Closed
wants to merge 1 commit into from

Conversation

glinscott
Copy link
Contributor

This is much faster for strings, and eventually when there is a
buffered reader of some sort, will be much faster for files.

Reading example.json 100 times before was around 1.18s.
After:

  • reading from string 0.68s
  • reading from file 1.08s (extra time is all in io::Reader)

Also:

This is much faster for strings, and eventually when there is a
buffered reader of some sort.

Reading example.json 100 times before was around 1.18s.
After:
- reading from string 0.68s
- reading from file 1.08s (extra time is all in io::Reader)
@huonw
Copy link
Member

huonw commented Jul 11, 2013

Looks awesome, but is there a particular reason this uses ~T rather than just T for the rdr field?

bors added a commit that referenced this pull request Jul 11, 2013
This is much faster for strings, and eventually when there is a
buffered reader of some sort, will be much faster for files.

Reading example.json 100 times before was around 1.18s.
After:
- reading from string 0.68s
- reading from file 1.08s (extra time is all in io::Reader)

Also:
- fixes #7611 - error when parsing strings and we hit EOF
- updates definition of whitespace in json should only be the 4 ascii whitespace chars
@bors bors closed this Jul 11, 2013
@glinscott
Copy link
Contributor Author

@huonw: no - that is due to my lack of experience in rust. I tried removing the ~ and it compiles fine, and the speed remains the same. From a semantic point of view, will that not cause a copy of T though?

@huonw
Copy link
Member

huonw commented Jul 11, 2013

The ~T does too: the T value has to be copied into the memory allocated by the ~ when you create it; moves of the ~T just copy the pointer (so one word), but copies allocate a new ~-box and copy the whole data across.

Most iterator objects are fairly small so the copies (with plain T) aren't expensive and they are unlikely to be a performance bottle neck anyway, unless one is parsing a huge number of very small JSON files. (If the writer of an iterator object is concerned about size, they could wrap it in a ~/@ themselves to make copies cheaper).

flip1995 pushed a commit to flip1995/rust that referenced this pull request Sep 28, 2021
…shearth

Tweak pedantic description for occasional FPs

changelog: none

Okay this is getting a bit picky (you might even say pedantic). I think we need to be careful not use the pedantic category as cover-all for lints with any amount of false positives. Lints with a high degree of FPs should be nursery or restriction IMO. If the pedantic category were to yield, say hypothetically, over 50% FPs, it would just be too annoying to use at all (to be sure, "too picky for me" is not a FP).

CC `@rust-lang/clippy`
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

Successfully merging this pull request may close these issues.

json module encodes invalid unicode code points in test
4 participants