-
Notifications
You must be signed in to change notification settings - Fork 70
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
Avoid parsing field name twice when matching named instruction in get_json_object
kernel
#2471
Conversation
Signed-off-by: Nghia Truong <[email protected]>
Signed-off-by: Nghia Truong <[email protected]>
This reverts commit 59ac5bf.
Signed-off-by: Nghia Truong <[email protected]>
Signed-off-by: Nghia Truong <[email protected]>
Signed-off-by: Nghia Truong <[email protected]>
94ea0ca
to
bd5645c
Compare
Signed-off-by: Nghia Truong <[email protected]>
Signed-off-by: Nghia Truong <[email protected]>
Signed-off-by: Nghia Truong <[email protected]>
This reverts commit a8d563c.
Signed-off-by: Nghia Truong <[email protected]>
ec4e2f9
to
b86615a
Compare
Signed-off-by: Nghia Truong <[email protected]>
This seems not providing much performance improvement. Probably because when parsing the field name a second time we jump back just a short distance to the previous data which is already in L2 cache and still not being evicted. Anyway, this is considered as a cleanup PR. |
build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
// check match if enabled | ||
if (!try_match_char(to_match, str.current_char())) { return std::make_pair(false, 0); } | ||
|
||
matched_field_name = matched_field_name && (to_match.is_null() || to_match.is_empty()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do this self assignment? matched_field_name = matched_field_name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an expression on boolean variable. In C++, such expressions can be short-circuit: the left operand is evaluated first, then the right operand is evaluated only if the left is true
. So this means we can avoid the overhead of evaluating the right side (to_match.is_null() ||...
) if matched_field_name
is already false
.
Because of such short-circuit functionality, there no exists the operators like &&=
, ||=
etc.
LGTM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests pass and I see a 1 to 2% performance improvement with this patch for my benchmarks.
This enhances
get_json_object
kernel by parsing each field name only once, doing both verifying its validity and checking if it is matched with a given string name at the same time. By doing so, it avoids parsing the field name twice as in the current implementation, reducing the kernel runtime to some extent.The PR also does some cleanup to the code. Not much performance improvement is observed.
Closes #2413.