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

Map preallocation #24

Open
scop opened this issue Oct 23, 2021 · 3 comments
Open

Map preallocation #24

scop opened this issue Oct 23, 2021 · 3 comments

Comments

@scop
Copy link
Contributor

scop commented Oct 23, 2021

Preallocation of maps can be useful, as shown by PR #23, would be nice to have prealloc suggest that too.

Just wondering how smart it can be made as things are not as straightforward as with slices because there's key uniqueness at play. Cases where the optimal preallocated capacity can be easily determined beforehand are more rare with maps, and in that sense suggesting it could have a worse signal to noise ratio. Maybe it should be made optional if it can't be made "smart enough" 🤔

@alexkohler
Copy link
Owner

Hey there, thanks for the issue! I'm not sure if we can realistically determine whether or not a given range or for loop with have duplicate key insertions into a map (we simply don't have access to that information using the AST). We could potentially suggest capacity hints, but as you mentioned, I think this may end up having more false positives than anything.

Happy to entertain contributions if you feel you can come up with something, feel free to experiment/open a PR 😄

@Antonboom
Copy link

+1 for map preallocation checking

@Porges
Copy link

Porges commented May 25, 2022

It should be possible at least to detect map→map copies?

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

4 participants