Skip to content

Accept large unsigned integers - #295

Merged
lemire merged 9 commits into
simdjson:developfrom
saka1:handle-unsigned
Sep 2, 2019
Merged

lemire merged 9 commits into
simdjson:developfrom
saka1:handle-unsigned

Conversation

@saka1

@saka1 saka1 commented Aug 21, 2019

Copy link
Copy Markdown
Contributor

This PR solves #68.
As far as I see, a new element type of the tape is necessary to handle unsigned large (> 2^63) value.
So I add the 'u' element for such values.

@lemire

lemire commented Aug 21, 2019

Copy link
Copy Markdown
Member

@saka1 Can you have a look at the failing tests?

@saka1

saka1 commented Aug 21, 2019

Copy link
Copy Markdown
Contributor Author

Oh... I'll try to fix 😱

@lemire

lemire commented Aug 22, 2019

Copy link
Copy Markdown
Member

Looks like we are passing the tests. That's great. Now we just need independent review (performance, correctness). If anyone wants to jump in, please do. Otherwise, this is on my todo.


inline bool is_integer() const { return get_type() == 'l'; }

inline bool is_unsigned_integer() const { return get_type() == 'u'; }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it be any positive integer?

In that case, I think I could easily add it to the fuzzer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, your suggestion is like below?

inline bool is_unsigned_integer() const {
  return get_type() == 'u' || (is_integer() && get_integer() >= 0);
}

This behavior seems consistent. But there is a little performance tradeoff.

Even if this is_unsigned_integer() returns true, only safe way to read the value is get_unsigned_integer() because get_integer() happens overflow for a large unsigned integer.
In such a situation, I think it's enough to check if the element type is 'u', so (is_integer() && get_integer() >= 0) is redundant.

Even so, should I do it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@saka1 I don't think that @ioioioio meant that you had to change something in the code/logic. However, what about documenting what is expected? That is, if I have the value "2"... what are the returned values for is_integer and is_unsigned_integer? (i.e., what should the users of the API expect?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about documenting what is expected?

I got it. I added some comments e7cb3d6.
@lemire @ioioioio How is it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, in fact I was asking if we wanted a behaviour similar to rapidjson's. Yes, something like what you described. Seems like it does not matter. In any case, Daniel did point out a real issue. The correction looks good to me.

I also thought that a behaviour like rapidjson's would be easier to test with the fuzzer. On a second thought, it should not be a lot more complicated.

Comment thread tests/integer_tests.cpp Outdated
@lemire

lemire commented Aug 23, 2019

Copy link
Copy Markdown
Member

Thanks @ioioioio

Help appreciated and further help invited!

@lemire

lemire commented Aug 23, 2019

Copy link
Copy Markdown
Member

Still on my todo.

@saka1

saka1 commented Aug 24, 2019

Copy link
Copy Markdown
Contributor Author

@lemire
Could you try to re-run the failed job?
I didn't make any meaningful changes in performance from the previous commits.

@lemire

lemire commented Aug 24, 2019

Copy link
Copy Markdown
Member

@saka1 Don't worry, we won't block PR based on failed perf tests.

We get many false positives. Sadly.

@lemire

lemire commented Aug 24, 2019

Copy link
Copy Markdown
Member

(We do assess performance, but right now it must be done manually... the CI is just interpreted as a warning.)

@lemire

lemire commented Aug 27, 2019

Copy link
Copy Markdown
Member

Still on my todo to review this.

@ioioioio

ioioioio commented Sep 1, 2019

Copy link
Copy Markdown
Member

I have added unsigned integers to the fuzzer: https://github.com/ioioioio/fuzzyjson/tree/add_uint

Ran the thing many times. Saw many big uint64. Everything went fine.

@lemire

lemire commented Sep 1, 2019

Copy link
Copy Markdown
Member

@ioioioio Thank you. So we are going to assume that it is correct.

I want to do a manual review before merging.

@lemire
lemire changed the base branch from master to develop September 2, 2019 14:49
@lemire
lemire merged commit c1f27fb into simdjson:develop Sep 2, 2019
@lemire

lemire commented Sep 2, 2019

Copy link
Copy Markdown
Member

@saka1 I am about to merge a slightly modified version of this PR. I would credit your name in the CONTRIBUTORS file, but I would need your actual name. You can issue a PR directly if you'd like.

lemire added a commit that referenced this pull request Sep 2, 2019
* handle uint64 value in JSON
* Add integer_tests
* Add get_unsigned_integer() on  ParsedJson::BasicIterator
* Write 'u' to tape when the value seems unsigned
* Add to handle 'u' element
* Brush up integer_tests.cpp
* Append tests/integer_tests in .gitignore
* Add comments to is_integer and is_unsigned_integer
@saka1

saka1 commented Oct 12, 2019

Copy link
Copy Markdown
Contributor Author

Sorry for the late reply.

@lemire @ioioioio: Many thanks for your reviews!!
I'll make a PR to add my name to the CONTRIBUTORS.

@saka1
saka1 deleted the handle-unsigned branch October 12, 2019 16:25
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.

3 participants