-
Notifications
You must be signed in to change notification settings - Fork 4
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
String collector API should only be noexcept if Collector()
is noexcept
#44
Comments
Are you considering using exceptions to improve performance? |
Not really as an exception should be way slower. But I want to experiment. The compiler has access to the whole code, so maybe it'd do control flow transformations and go away with the exception. In any case, the string collector API may be a |
The collector is used in a critical part of the code where performance is important. It is possible to work around the I acknowledge that this is different from your pattern matching use case. |
I don't mean to make the collector API
Fair enough.
I still have to run benchmarks. Using |
That's a killer argument for the I'll think more about the problem. In the meantime...
What do you think about |
Actually, there's a better way for my pattern matching. I must be stupid for not realizing this sooner. I could collect the string once in a static array whose capacity is N + 1 where N is the size of the largest string in the static search set. I'll implement this change over the weekend. So both downsizes are avoided — dynamic allocation and decoding same value multiple times. |
Well, here is the new approach. I'm only pasting the code for the record. This take is pretty straight-forward and not worth discussing IMO. |
Here's a different idea. Trial.Protocol splits match and decode steps. This is beneficial when we're not interested in the decoded values. The performance benefit is very real and very measurable. It's not only useful for performance, but this flexibility allows However merging match and decoding steps can be useful for performance when you know you're interested in the value. Trial.Protocol interface for matching is: reader.next(); Could you keep the following in the back of your mind for a few days to decide what you think? // new overload
reader.next(matching_options);
Loops such as: for (;;) {
// ...
auto current_key = reader.value<std::string>();
if (current_key == "foo") {
if (!reader.next()) throw Error();
reader.string(msg.foo);
if (!reader.next()) throw Error();
} else if (current_key == "bar") {
if (!reader.next()) throw Error();
reader.string(msg.bar);
if (!reader.next()) throw Error();
} else {
if (!reader.next()) throw Error();
json::partial::skip(reader);
}
} Could become: for (;;) {
// ...
auto current_key = reader.value<std::string>();
if (current_key == "foo") {
// MatchCollector here is a user-defined class that already fills
// the required user-customization points
if (!reader.next(MatchCollector(msg.foo))) throw Error();
if (reader.symbol() != json::token::symbol::string) throw Error();
if (!reader.next()) throw Error();
} else if (current_key == "bar") {
if (!reader.next(MatchCollector(msg.bar))) throw Error();
if (reader.symbol() != json::token::symbol::string) throw Error();
if (!reader.next()) throw Error();
} else {
if (!reader.next()) throw Error();
json::partial::skip(reader);
}
} Do notice that the same idea can be used to fill the Another useful member to auto head = /* ... */;
auto val = json::partial::parse(reader, my_match_options);
auto tail = my_match_options.tail;
std::string_view lit(head, tail - head); I had this |
Is the purpose of this API to improve usability or to get better performance? The reason i ask is because most of the |
The idea is to avoid walking over the string/token twice, so performance. You can ignore the |
I've kept cooking the The idea is for the |
I've been experimenting on using exceptions to bail out early of undesired keys, but then stumbled on the
noexcept
problem: https://github.com/vinipsmaker/trial.protocol/blob/203e70548a504fb63ba4230826d01f446f9b560d/include/trial/protocol/json/scan.hpp#L426The text was updated successfully, but these errors were encountered: