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

Feature/speed up set other status #1239

Merged
merged 6 commits into from
May 9, 2024
Merged

Conversation

hakuturu583
Copy link
Collaborator

@hakuturu583 hakuturu583 commented May 1, 2024

Description

Abstract

Replace non-efficient implementation in EntityBase::setOtherStatus function

Background

scenario_simulator_v2 was too slow, so we have to speed up for supporting a lot of entities.

In previous version, EntityBase::setOtherStatus function was this.

void EntityBase::setOtherStatus(
  const std::unordered_map<std::string, CanonicalizedEntityStatus> & status)
{
  other_status_.clear(); // clear previous status
  for (const auto & [other_name, other_status] : status) {
    if (other_name != name) {
      other_status_.emplace(other_name, other_status); // emplace status if the status comes from another entity.
    }
  }
}

It was not efficient.

Details

So, I replace it as

void EntityBase::setOtherStatus(
  const std::unordered_map<std::string, CanonicalizedEntityStatus> & status) {
  other_status_ = status;
  other_status_.erase(name);
}

This PR is depends on #1237 and #1238

References

#1237
#1238

performance

before

Screenshot from 2024-05-09 10-05-57

This process took up 2.2% of the total processing time.

after

Screenshot from 2024-05-09 10-06-36

This process now takes 1.5% of the total processing time.

Destructive Changes

N/A

Known Limitations

N/A

Copy link

github-actions bot commented May 1, 2024

Checklist for reviewers ☑️

All references to "You" in the following text refer to the code reviewer.

  • Is this pull request written in a way that is easy to read from a third-party perspective?
  • Is there sufficient information (background, purpose, specification, algorithm description, list of disruptive changes, and migration guide) in the description of this pull request?
  • If this pull request contains a destructive change, does this pull request contain the migration guide?
  • Labels of this pull request are valid?
  • All unit tests/integration tests are included in this pull request? If you think adding test cases is unnecessary, please describe why and cross out this line.
  • The documentation for this pull request is enough? If you think adding documents for this pull request is unnecessary, please describe why and cross out this line.

@hakuturu583 hakuturu583 added bump patch If this pull request merged, bump patch version of the scenario_simulator_v2 bump minor If this pull request merged, bump minor version of the scenario_simulator_v2 and removed bump minor If this pull request merged, bump minor version of the scenario_simulator_v2 labels May 1, 2024
@hakuturu583 hakuturu583 self-assigned this May 2, 2024
@hakuturu583 hakuturu583 requested a review from HansRobo May 8, 2024 13:45
@hakuturu583 hakuturu583 marked this pull request as ready for review May 8, 2024 13:46
@HansRobo HansRobo merged commit dd66419 into master May 9, 2024
14 checks passed
@github-actions github-actions bot deleted the feature/speed_up_set_other_status branch May 9, 2024 04:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bump patch If this pull request merged, bump patch version of the scenario_simulator_v2 wait for regression test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants