Repository navigation
Conversation
|
It is a good idea, but adding a boolean is not going to be nice. Here is my recommendation. Drop the bigint Boolean. Undo your work. Then add something like... near were Then, at a couple of places, replace And... in simdjson/src/internal/error_tables.cpp Line 20 in 88bf5cb Doing so will make some of our tests fail, but it should easy to fix. The documentation may need to be updated slightly. It should not be very difficult. It will be a great feature!!! |
lemire
left a comment
There was a problem hiding this comment.
This is a superb contribution, but what we want is to return a different error (not NUMBER_ERROR). Adding a new bool and changing function signatures is unnecessary and burdensome.
This is pretty much what I initially did, but then thought it would present backward compatibility issues, so I scratched that and introduced this less intrusive backward-compatible version. :) So, if you are ok with the appoach you suggested, I can revert to my prior changes. |
|
It is a change but we never committed to a fixed set of error codes. We shall warn our users. |
|
LMK what you think of this version |
|
I like it! It is very clean. @saleyn Can you check the failing tests? I think that these are expected. They relate to the fact that the change is breaking in some sense. |
|
@lemire, I have a question about |
We generally handle the special case where the document is a scalar value (string, number, null, etc.) in this manner. We create a temporary buffer, we copy the data to the buffer and parse it from the buffer. It is very uncommon that documents take this form, so we do not care much about the performance. Using a temporary buffer ensures that we can use the same code we generally use, instead of having to deal with two different code paths... We just want to reduce our maintenance and make bugs less likely. |
|
The reason I am asking is because in case of a big integer we don't know the size of the buffer upfront, and it wouldn't be possible to preset that statically on the stack. Would it be ok to use the pointers in that case to the source json, or you suggest otherwise? |
|
Yes. |
|
@saleyn I am planning a release soon, if you ever get some time to finish this PR, we could include it. |
|
Thanks for letting me know. I'll try to finish it within a week or so. |
|
@lemire, I've been traveling for the past few days and didn't get to finish the changes in PR yet. Hopefully will do by the end of this week. |
|
@saleyn That's ok. We have a bunch of new changes, and I'll wait for your component for the release. |
|
I completed the necessary changes. The tests pass, however, @lemire, do you mind taking a look at why the CIFuzz is failing? I am uncertain about the cause. |
|
@saleyn I'll work on it today. I am planning on a release soon after. |
|
I force pushed a small update. |
| os << element.get_uint64().value_unsafe() << endl; | ||
| break; | ||
| case simdjson::dom::element_type::BIGINT: | ||
| os << element.get_bigint().value_unsafe() << endl; |
There was a problem hiding this comment.
This appears to be unsafe according to our CI.
There was a problem hiding this comment.
I think I understand the root cause. Let me see.
There was a problem hiding this comment.
I don't think your fix is correct. The issue here is where do you store the data in the DOM model. You cannot rely on the document being around.
There was a problem hiding this comment.
The other problem is that a bigint_t is not a 64-bit type, so the payload union is incorrect.
Adding bigint support to the DOM API requires more work.
There was a problem hiding this comment.
Yes, the commit below was my initial thought this morning, but right after that I realized the problem was related to the code inside tape_writer::append_bigint(...), which you also noted down below. I haven't had time this morning to investigate it further. Will try to check this tonight.
| } | ||
|
|
||
| simdjson_inline void tape_writer::append_bigint(const uint8_t *const src, const uint8_t *const end) noexcept { | ||
| append(end - src, internal::tape_type::BIGINT); |
There was a problem hiding this comment.
Where is the bigint written? Note that the DOM tape is meant to be complete, it does not include a reference to the original document. You could write it to the string buffer, but as far as I can tell, it is not done now.
There was a problem hiding this comment.
Thanks! This morning I also saw that this part was incorrect.
| double floating_point_number; | ||
| int64_t signed_integer; | ||
| uint64_t unsigned_integer; | ||
| bigint_t big_integer; |
There was a problem hiding this comment.
The union is meant to span 64-bit. A bigint_t is not a 64-bit data structure.
It is also very much unlike the other values because it requires a variable-length amount of memory (possibly on the string buffer).
There was a problem hiding this comment.
I see. The 64bit union size restriction wasn't obvious by reading the code, which is why I thought that it didn't matter. Where is it in the code that expects the size of the number struct to be 64 bits?
There was a problem hiding this comment.
Where is it in the code that expects the size of the number struct to be 64 bits?
The union is at least as big as necessary to hold its largest data member. Currently, all values use 64 bits so there is no waste. By introducing a type that is almost surely larger (I expect an std::string_view to span 16 bytes typically), the number type is thus made larger.
How this affects the code and its performance is hard to tell in the abstract, but we cannot assume that it is free. It could be free, but we have to prove that it is so.
We should try to optimize for the common case. And the common case is that there is no big integer. We do not want everyone to be paying the price for the uncommon cases when there are big integers...
Now, it is possible that your design is correct and that there is no trade-off but my instinct is to make the big integer case exceptional.
In any case, we have to remember that the big integer type is not usable as is. That is, you get a string-view. You are still going to need to parse it into a usable type. So it is bound to be a special case.
In any case, we need to justify the design and make sure we don't make everyone's code slower for a feature that very few people will ever use. That is not meant to be discouraging... for some people, your implementation might be absolutely super useful... but we don't want to trade that for slower performance everywhere else.
There was a problem hiding this comment.
Overall, this is pretty good code and the ideas are quite nice, but it raises questions.
The initial PR memory detected the big integers and reported a corresponding error. This was non-invasive and relatively easy. This left the parse_number function unchanged. For users relying on on-demand, the big-integer error can be followed by a token access and so we could support big integer in on-demand in a manner that is functionally equivalent to the one in this PR, but with far fewer changes to the core library.
I would recommend you still consider this approach due to its simplicity.
More recently, the scope changed significantly, with the introduction of a bigint_t type which is essentially an std::string_view. The DOM tape format is also changed by this PR, but the tape.md file documenting the format was not changed, so it is not clear whether the format is correct. Importantly, we need for the data to appear somewhere in the tape data structure, possibly copied to the string buffer.
The PR also appears to introduce significant changes to the parse_number function. This might be fine, but we cannot merge it without assessing the effect on performance.
Nevertheless, we can adopt the more ambitious approach. It will require more effort, however.
Please consider the following tasks:
- The new tape format needs to be documented. Please edit the
tape.mdfile and explain how a big int is stored. - I don't think that the payload union can include
bigint_t. I think that the design is wrong given how different a big int is. - We need before/after benchmarks. Please follow the following instructions (I am assuming that you are under Linux, macOS or a similar system):
cmake -B build -D SIMDJSON_DEVELOPER_MODE=ON
cmake --build build --target bench_ondemand --target parse
./build/benchmark/dom/parse jsonexamples/twitter.json
./build/benchmark/bench_ondemand --benchmark_filter="kostya<simdjson"
Build and run the benchmarks before and after the changes. Even better, if you can, run them as a privileged user so that we can get performance counters.
Ideally, we should not see a performance penalty as a result of this PR when big integers are not encountered. That is, we don't want to pay for supporting big integers when they are not present.
Importantly, also, we do not want to introduce new bugs. Thus I have a fourth task:
- We need more extensive dedicated tests regarding big integers.
|
@lemire, thank you for your extensive comments!
Unfortunately with the recent traveling and timing gaps in working on this PR I can't recall what issue I ran into that forced me to change the direction and implement the more intrusive approach. :( I could try to revert and go back to that original approach and then attempt to do this one incrementally. However, I have another business trip abroad next week and will be out for two more weeks. So, won't be able to focus on this code for a while.
That was my oversight. I'll modify it tonight.
Will do.
I added one such test to the |
|
@saleyn You may need to sync with our main branch for the tests to run. :-) |
Yes. This is fine... in theory... but the PR introduces a change in the front-facing API that might affect many people. The library used to reject some numbers, now it will accept them. This can break code. It is not like we are offering a way to opt-in. You get big integers whether you want them or not. So it should be pretty good otherwise we might break systems. |
Co-authored-by: Daniel Lemire <[email protected]>
Co-authored-by: Daniel Lemire <[email protected]>
Co-authored-by: Daniel Lemire <[email protected]>
Co-authored-by: Daniel Lemire <[email protected]>
Co-authored-by: Daniel Lemire <[email protected]>
Co-authored-by: Daniel Lemire <[email protected]>
Co-authored-by: Daniel Lemire <[email protected]>
|
Benchmark results DOM parser NOTE: the values differ from run to run, but the master branch does have a slight edge. Let me know if you consider these results significant. The main question is if using a 128 bits
OnDemand Parser
|
|
@saleyn The performance looks good. The fuzzers indicate that we probably have a safety issue. |
|
Another unrelated improvement suggestion would be to add simdjson_inline error_code array::consume() noexcept {
auto error = iter.json_iter().skip_child(iter.depth()-1);
if(error) [[unlikely]] { iter.abandon(); }
return error;
}Given that there are a lot of places containing such branching, it may have some performance benefit. |
This is a fair topic to investigate. If get good results, please issue a separate pull request. Of course, these are keywords introduced in C++20 and we want the main library to support C++11. In simdjson, we have |
|
I recalled why I decided to do a more intrusive change. The issue was the question of what |
This extention adds the ability to identify the cause of number parsing failure due to a number not fitting in the 64-bit space.