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

Performance issue with the redundancy operations #3

Open
yyzdtccjdtc opened this issue May 10, 2022 · 5 comments
Open

Performance issue with the redundancy operations #3

yyzdtccjdtc opened this issue May 10, 2022 · 5 comments

Comments

@yyzdtccjdtc
Copy link
Contributor

let view = self.view();

This view() function will create a ClustersView structure inside a loop, but for the rest code of this loop, only the width, height and clusters_indices will be used. And for every loop iteration, this view() function will create the same values again and again which introduce a lot of redundancy operations. Perhaps we can dispense with this view() function and instead directly reference the self first and then get the needed variables inside these functions.

If we change the code of

.neighbours(&view)

Into

.neighbours(&self)

(Need to do some modifications with the neighbours() function)

Change

let deepen = if self.hierarchical == HIERARCHICAL_MAX {
(self.deepen)(&view, &self.get_cluster(index), &infos)

Into

            let deepen = if self.hierarchical == HIERARCHICAL_MAX {
                (self.deepen)(&self, &self.get_cluster(index), &infos)

(Need to modified the deepen function too.)

Change

let hollow = (self.hollow)(&view, &self.get_cluster(index), &infos);

Into

let hollow = (self.hollow)(&infos);

Then comment out the line 401 and 436.

let view = self.view();

let view = self.view();

Then it can avoid these redundant operations.

According to my test it will get a 43.8% speedup (7.3s to 5.1s) with the vtracer application (https://github.com/visioncortex/vtracer).

Hope this information helps!

@tyt2y3
Copy link
Member

tyt2y3 commented May 11, 2022

That's outrageous number! Just a sanity test, did you benchmark it with --release?
It's a bad coding pattern actually. I think we should copy all methods to the Cluster itself so that view() is no longer needed.
On the other hand, what's preventing LLVM from optimizing things? Can we add an #[inline] to view() and see if that does the trick?

@tyt2y3
Copy link
Member

tyt2y3 commented May 11, 2022

Anyway, welcome!

@yyzdtccjdtc
Copy link
Contributor Author

@tyt2y3
Hi Chris,

Yes, I am testing it with the --release and set opt-level = 3 in the Cargo.toml file. According to the output file from the objdump, this is not optimized because this view() function stores these values from the registers on the stack and then takes them out of the stack when they are needed. So I believe that this inline keyword does not change anything, and my test also shows that the running time did not change after adding this inline keyword for view() function.

@tyt2y3
Copy link
Member

tyt2y3 commented May 14, 2022

Sad. Thank you for the investigation. PR would be welcomed. Though I would prefer keeping the view() function in place because other crates depended on it.

@yyzdtccjdtc
Copy link
Contributor Author

Hi, I submitted a pull request. Here's the link #5 (comment)

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

No branches or pull requests

2 participants