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

Reduce object allocations by using sort_by! where it is safe #924

Closed

Conversation

czj
Copy link
Contributor

@czj czj commented Jun 21, 2023

Calling .keys() always returns a new array, so we can use sort_by!() to prevent allocating a new array.

@minad
Copy link
Member

minad commented Jun 21, 2023

The lists are not long and this happens only during parser initialization. Is there a reason why you think we need this optimization? If you want to optimize, I'd prefer a more profile-driven approach instead of applying micro optimizations.

@minad minad closed this Jun 21, 2023
@czj czj deleted the reduce-object-allocations-on-sort-by branch June 21, 2023 13:45
@czj
Copy link
Contributor Author

czj commented Jun 21, 2023

That was simply detected and applied by static analysis.

@minad
Copy link
Member

minad commented Jun 21, 2023

Okay, I am fine with such changes as long as we add the linter and/or the static analyzer to the CI pipeline. Which one did you use?

@minad
Copy link
Member

minad commented Jun 21, 2023

In the other PR you proposed to add rubocop to the CI. I'd appreciate that.

@czj
Copy link
Contributor Author

czj commented Jun 21, 2023

I used the configuration we use @levups in CI : it uses Rubocop with Standard Ruby rules as its base, plus uses rubocop-capybara, rubocop-minitest, rubocop-performance, rubocop-rails, rubocop-rake, rubocop-thread_safety (not all relevant for this project).

I also activated unsafe cops corrections + cops that are disabled by default (like those for performance). That should not be default but by reading warnings you can find some.

@czj
Copy link
Contributor Author

czj commented Jun 21, 2023

In the other PR you proposed to add rubocop to the CI. I'd appreciate that.

We then need to agree on the code style you wish to use. Using Standard Ruby is a standard, sane, no-configuration option. Using a custom Rubocop configuration that matches the current code style is another one.

To run Rubocop / Standard on CI and comment on PRs we use Pronto via GitHub Actions.

Output looks like this :

image

I can apply it to this repo.

@minad
Copy link
Member

minad commented Jun 21, 2023

The standard configuration is likely a good starting point for the CI. I am not sure if using pronto is a good idea in the longer run. I prefer to add "plain" rubocob to the actions file without an additional middleman.

@czj
Copy link
Contributor Author

czj commented Jun 21, 2023 via email

@minad
Copy link
Member

minad commented Jun 21, 2023

That's a good point. I will take a look at it.

@czj
Copy link
Contributor Author

czj commented Jun 21, 2023

Great. Done in #925 and #926

This was referenced Jun 21, 2023
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.

2 participants