Skip to content

PathUtil.smart_path causes performance issue on case large amount of offenses #9802

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

Open
keymastervn opened this issue May 16, 2021 · 1 comment
Labels
enhancement performance Tickets related to RuboCop's performance

Comments

@keymastervn
Copy link

keymastervn commented May 16, 2021

Is your feature request related to a problem? Please describe.

I am using CLI to generate a custom rule, so far there are around 15K offenses in my codebase. I want to display them as clang formatter, however, it is slow-ish.

Then I try emacs formatter, feeling that it is very fast compared to the clang. I dive deep into the code and see the code related to relative path in clang. The code is calling Dir.pwd as base_dir every time smart_path called in the formatter.

Describe the solution you'd like

Perhaps when running rubocop it should not be called every time, I'd like to perform caching on Dir.pwd as calling it is expensive. Either caching in runtime using memoized class variable or set it as a CONST to ignore the recall.

Describe alternatives you've considered

N/A

Additional context

I've made a benchmark, so far it is 1xx times slower if we keep the old non-cached way Dir.pwd. Greatly impact folks who are running it with a large number of offenses, or first time maybe.
https://gist.github.com/keymastervn/16d2e08d1c62d172dd830a3634e7a8cf

@bbatsov bbatsov added enhancement performance Tickets related to RuboCop's performance labels Aug 30, 2021
@fatkodima
Copy link
Contributor

@keymastervn Can you verify this is still happening on the master?

I tested on gitlab's codebase with ~16k offenses and #smart_path method took only 0.4% of the total time. You can see an example from https://github.com/rubocop/rubocop/blob/master/bin/rubocop-profile file on how to profile rubocop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement performance Tickets related to RuboCop's performance
Projects
None yet
Development

No branches or pull requests

3 participants