-
Notifications
You must be signed in to change notification settings - Fork 191
optimize goal_count (callgrind ir/call : 816 -> 126) #237
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -15,15 +15,23 @@ GoalCountHeuristic::GoalCountHeuristic( | |||||||||
| if (log.is_at_least_normal()) { | ||||||||||
| log << "Initializing goal count heuristic..." << endl; | ||||||||||
| } | ||||||||||
| goals.reserve(task_proxy.get_goals().size()); | ||||||||||
| for (FactProxy goal : task_proxy.get_goals()) { | ||||||||||
| int var = goal.get_variable().get_id(); | ||||||||||
| int val = goal.get_value(); | ||||||||||
| goals.push_back({var,val}); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| int GoalCountHeuristic::compute_heuristic(const State &ancestor_state) { | ||||||||||
| State state = convert_ancestor_state(ancestor_state); | ||||||||||
| int unsatisfied_goal_count = 0; | ||||||||||
|
|
||||||||||
| for (FactProxy goal : task_proxy.get_goals()) { | ||||||||||
| const VariableProxy var = goal.get_variable(); | ||||||||||
| if (state[var] != goal) { | ||||||||||
| state.unpack(); | ||||||||||
| const vector<int> &unpacked_state = state.get_unpacked_values(); | ||||||||||
| for (const auto& it : goals) { | ||||||||||
| const int& var = it.first; | ||||||||||
| const int& val = it.second; | ||||||||||
|
Comment on lines
+32
to
+33
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
We'd generally copy the values here instead of taking a reference. Should be equally fast as creating a reference.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, now that we have C++20, this should work as well: for (auto[var, val] : goals) {
...
} |
||||||||||
| if (unpacked_state[var] != val) { | ||||||||||
| ++unsatisfied_goal_count; | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,8 @@ | |
|
|
||
| namespace goal_count_heuristic { | ||
| class GoalCountHeuristic : public Heuristic { | ||
| // caching the goals, avoiding FactProxy | ||
| std::vector<std::pair<int,int>> goals; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line could use a comment explaining that the goals are stored here for performance reasons.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we run an experiment to have numbers on performance? callgrind data is useful, but usually not conclusive. The VM has its own issues when comparing to actual performance on hardware, and due to the vagaries of inlining, runtime can shift from one place to another in a way that makes it hard to draw conclusions from the profile data alone.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used the code for implementing BFWS which uses goalcount. The difference was significant. I also observed similar bottlenecks from ***Proxy while implementing other parts of BFWS code.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I measured the difference in the release build on ipc instances. I lost the data though
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
done
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could re-run the experiment on our servers but it might take me some time to get around to it. It would help if you prepare a revision of the code that is in between this one and the main branch, where you only do the precomputation/storing of the goals, still using fact proxies in the heuristic computation. This way, we can separate the impact of this and the change avoiding the fact proxies. |
||
| protected: | ||
| virtual int compute_heuristic(const State &ancestor_state) override; | ||
| public: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.