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

Optimize TreeMetricResult#descendant_values #224

Merged
merged 2 commits into from
Jul 23, 2016

Conversation

rafamanzo
Copy link
Member

@rafamanzo rafamanzo commented Jul 22, 2016

The previous implementation was incredibly sub-optimal. It can be easily
replaced with a join on the parent_id.

Aggregation performance test results below:

Metric Count Branch Wall Time (s) Process Time (s)
1 v1.3.2 34.16732797622681 29.564079139199997
1 improve_descendant_values 23.588372707366943 21.618301714000005
2 v1.3.2 71.57923197746277 63.06931912939999
2 improve_descendant_values 47.487600564956665 46.2433640588
4 v1.3.2 154.1164906024933 147.8050995992
4 improve_descendant_values 97.7507544517517 70.0752864698
8 v1.3.2 333.3348692417145 311.43665788299995
8 improve_descendant_values 190.28073539733887 226.78861793199994

@mezuro/core we need a third pair of eyes here as well.

This is part of #207.

The previous implementation was incredibly sub-optimal. It can be easily
replaced with a join on the parent_id.
@danielkza
Copy link
Contributor

danielkza commented Jul 22, 2016

Here are some tests on my machine, including max. resident RAM (all using 8 metrics). Files are named for the respective branches. Gist.

In short, this is a really (almost 100%) performance good improvement by itself, but still quite a bit worse than the full aggregation rewrite (which actually doesn't even use descendant_values anymore!).

👍 for me

It was only used by the old version of
TreeMetricResult#descendant_values.
@rafamanzo
Copy link
Member Author

Even tough this will have no impact on aggregation after #225, it will still be used for MetricResultsController and the code legibility improvement is nice as well.

Nice job!

(I've removed some code made useless by this)

@danielkza
Copy link
Contributor

Right, I missed that. Nice catch on the useless code!

self.class.
joins(:module_result).
where('module_results.parent_id' => module_result_id).
pluck(:value)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice 👏

@diegoamc diegoamc merged commit ed7c75a into master Jul 23, 2016
@diegoamc diegoamc deleted the improve_descendant_values branch July 23, 2016 16:58
@diegoamc
Copy link
Contributor

Great job, guys!

@rafamanzo rafamanzo mentioned this pull request Jul 27, 2016
5 tasks
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.

3 participants