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 #163

Closed
yyzdtccjdtc opened this issue May 2, 2022 · 1 comment
Closed

Performance issue with the redundancy operations #163

yyzdtccjdtc opened this issue May 2, 2022 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@yyzdtccjdtc
Copy link
Contributor

https://github.com/sharkdp/pastel/blob/master/src/distinct.rs#L329-L324

For line 329 here, the &colors[color] will keep loading the same value from the same memory location in this for loop, because the index color will not change. If we declare a new variable at_color outside of this for loop and reference it into to the self.distance() function then it can save a lot of memory operations because this at_color will be put into register by the compiler. According to my test with generate 4000 distinguished colors, it will get a 5.4% speedup.

https://github.com/sharkdp/pastel/blob/master/src/distinct.rs#L168

For line 168 here, every element in the new_colors vector is a tuple (Color, Lab), but for the result.update() function, it will only use the Lab elements, so there's some waste memory to copy and update the color. And if it only pass a vector of Lab, then there will be a 13.4% speed up with the previous optimization together.

Here is the modified code:

distinct-modified.txt

Hope these information helps!

@sharkdp
Copy link
Owner

sharkdp commented May 15, 2022

Awesome, thank you very much! If you are okay with using your code under pastels LICENSE, it would be great if someone could open a PR with the necessary changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants