Skip to content

perf(label_table): add TryGetIdByLabel to avoid exception overhead#1740

Merged
inabao merged 3 commits into0.16from
cp-1701-to-0.16
Mar 26, 2026
Merged

perf(label_table): add TryGetIdByLabel to avoid exception overhead#1740
inabao merged 3 commits into0.16from
cp-1701-to-0.16

Conversation

@inabao
Copy link
Copy Markdown
Collaborator

@inabao inabao commented Mar 23, 2026

Summary

Changes

The 0.16 branch has a different LabelTable structure compared to main, so the changes were adapted accordingly:

  • Added TryGetIdByLabel method that returns std::pair<bool, InnerIdType> instead of throwing exceptions
  • The method is noexcept to avoid exception handling overhead
  • GetIdByLabel now delegates to TryGetIdByLabel for code reuse

Original PR: #1701

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: jinjiabao.jjb <jinjiabao.jjb@antgroup.com>
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the LabelTable's efficiency by introducing a non-throwing mechanism for checking label existence. By providing a TryGetIdByLabel method that returns a boolean success indicator along with the ID, the system can avoid the performance penalty associated with exception handling in common lookup scenarios. The existing GetIdByLabel method was then updated to leverage this new, more performant internal check.

Highlights

  • Performance Improvement: Introduced a new TryGetIdByLabel method to the LabelTable class, designed to avoid the overhead of exceptions when checking for label existence.
  • API Change: The new TryGetIdByLabel method returns a std::pair<bool, InnerIdType> to indicate success and the ID, and is marked noexcept.
  • Code Refactoring: Refactored the existing GetIdByLabel method to internally utilize the new TryGetIdByLabel method, promoting code reuse and consistency.
  • Branch Adaptation: This change is a cherry-pick from PR perf(label_table): add TryGetIdByLabel to avoid exception overhead #1701, adapted specifically for the 0.16 branch due to differences in the LabelTable structure.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a TryGetIdByLabel method to avoid exception overhead, which is a good performance optimization. The implementation is clean and GetIdByLabel is refactored to use the new method. I have a couple of suggestions: one to further improve performance by avoiding a potential double map lookup, and another for a minor grammar fix in an error message.

Comment on lines 85 to +88
if (this->label_remap_.count(label) == 0) {
throw std::runtime_error(fmt::format("label {} is not exists", label));
return {false, 0};
}
return this->label_remap_.at(label);
return {true, this->label_remap_.at(label)};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

To improve performance, you can use find to avoid a potential double lookup in the map. Using count and then at might perform two lookups. The if with initializer statement (C++17) can make the code more concise here.

Suggested change
if (this->label_remap_.count(label) == 0) {
throw std::runtime_error(fmt::format("label {} is not exists", label));
return {false, 0};
}
return this->label_remap_.at(label);
return {true, this->label_remap_.at(label)};
if (auto it = this->label_remap_.find(label); it != this->label_remap_.end()) {
return {true, it->second};
}
return {false, 0};

GetIdByLabel(LabelType label) const {
auto [success, inner_id] = TryGetIdByLabel(label);
if (not success) {
throw std::runtime_error(fmt::format("label {} is not exists", label));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

A minor grammar fix in the error message for better clarity.

Suggested change
throw std::runtime_error(fmt::format("label {} is not exists", label));
throw std::runtime_error(fmt::format("label {} does not exist", label));

@inabao inabao self-assigned this Mar 23, 2026
@inabao inabao added version/0.16 kind/improvement Code improvements (variable/function renaming, refactoring, etc. ) labels Mar 23, 2026
@inabao inabao force-pushed the cp-1701-to-0.16 branch 2 times, most recently from c015e2e to 758e4f5 Compare March 23, 2026 08:53
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 23, 2026

Codecov Report

❌ Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.

@@            Coverage Diff             @@
##             0.16    #1740      +/-   ##
==========================================
- Coverage   92.22%   92.12%   -0.10%     
==========================================
  Files         295      295              
  Lines       15708    15714       +6     
==========================================
- Hits        14486    14477       -9     
- Misses       1222     1237      +15     
Flag Coverage Δ
cpp 92.12% <83.33%> (-0.10%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
common 92.66% <77.77%> (+0.04%) ⬆️
datacell 91.57% <ø> (-0.84%) ⬇️
index 91.45% <100.00%> (+0.24%) ⬆️
simd 100.00% <ø> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fd60a62...cc76055. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

inabao added 2 commits March 26, 2026 11:29
Cherry-pick of PR #1701 to 0.16 branch with adaptations for the different
LabelTable structure in this branch.

Signed-off-by: jinjiabao.jjb <jinjiabao.jjb@antgroup.com>
Copy link
Copy Markdown
Collaborator

@LHT129 LHT129 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Collaborator

@wxyucs wxyucs left a comment

Choose a reason for hiding this comment

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

lgtm

@inabao inabao merged commit 9b4fd66 into 0.16 Mar 26, 2026
23 checks passed
@inabao inabao deleted the cp-1701-to-0.16 branch March 26, 2026 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/improvement Code improvements (variable/function renaming, refactoring, etc. ) size/S version/0.16

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants