Skip to content
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

Merged
merged 12 commits into from
Oct 11, 2024

Conversation

ttnghia
Copy link
Collaborator

@ttnghia ttnghia commented Oct 5, 2024

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.

@ttnghia ttnghia self-assigned this Oct 5, 2024
@ttnghia ttnghia changed the base branch from branch-24.10 to branch-24.12 October 5, 2024 04:13
Signed-off-by: Nghia Truong <[email protected]>
@ttnghia ttnghia force-pushed the improve_get_json_obj branch from 94ea0ca to bd5645c Compare October 6, 2024 05:41
Signed-off-by: Nghia Truong <[email protected]>
Signed-off-by: Nghia Truong <[email protected]>
Signed-off-by: Nghia Truong <[email protected]>
Signed-off-by: Nghia Truong <[email protected]>
@ttnghia ttnghia force-pushed the improve_get_json_obj branch from ec4e2f9 to b86615a Compare October 7, 2024 17:54
Signed-off-by: Nghia Truong <[email protected]>
@ttnghia ttnghia marked this pull request as ready for review October 7, 2024 18:00
@ttnghia
Copy link
Collaborator Author

ttnghia commented Oct 7, 2024

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.

@ttnghia
Copy link
Collaborator Author

ttnghia commented Oct 7, 2024

build

Copy link
Collaborator

@thirtiseven thirtiseven left a 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());
Copy link
Collaborator

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

Copy link
Collaborator Author

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.

@res-life
Copy link
Collaborator

LGTM

Copy link
Collaborator

@revans2 revans2 left a 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.

@ttnghia ttnghia merged commit 024b9c6 into NVIDIA:branch-24.12 Oct 11, 2024
3 checks passed
@ttnghia ttnghia deleted the improve_get_json_obj branch October 11, 2024 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEA] Avoid parsing field name twice when matching named instruction in get_json_object
4 participants