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

chore(stats): improve get_line_charts for ReadService #1037

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yjhmelody
Copy link
Contributor

Reduce some clone for the function.

@@ -68,12 +68,12 @@ fn map_read_error(err: ReadError) -> Status {
///
/// Returns `None` if info were not found for some chart.
fn add_chart_info_to_layout(
layout: Vec<types::LineChartCategory>,
chart_info: BTreeMap<String, EnabledChartEntry>,
layout: &[types::LineChartCategory],
Copy link
Contributor

@bragov4ik bragov4ik Aug 29, 2024

Choose a reason for hiding this comment

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

I agree with chart_info, but I think it should be cheaper to perform 1 big clone instead of multiple small (equivalent) clones for layout

Copy link
Contributor Author

@yjhmelody yjhmelody Aug 29, 2024

Choose a reason for hiding this comment

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

they are in heap,so i think its no difference,but only parts of fields need to be cloned,so i think it will be cheaper

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, probably there's no difference because of strings.

However, intersect_info effectively clones whole LineChartCategory, so I don't see a reason to use reference where move semantics fits ideally. I think it's a good practice to leave decision to clone or not for the caller.

Copy link
Contributor

Choose a reason for hiding this comment

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

I.e.

  • id - cloned directly
  • title - cloned directly
  • charts_order - .iter() then clone on each element

@sevenzing sevenzing changed the title chore: improve get_line_charts for ReadService chore(stats): improve get_line_charts for ReadService Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants