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

Pre-allocate slice in generic Map function #469

Merged
merged 1 commit into from Feb 29, 2024

Conversation

jwilsson
Copy link
Contributor

Hey!
Thanks for this great library, really helped me out with some scraping!

I noticed that the generic Map function just added the other week always appends, growing the slice as needed instead of pre-allocating it upfront.

Benchmark results from my M1:

Without pre-allocation:
BenchmarkMap-10                              	  238780	      5140 ns/op

With pre-allocation:
BenchmarkMap-10                              	  277968	      4317 ns/op

If you think it's not worth it, no hard feelings. Just thought it would be a fun, easy, optimization to make.

@mna
Copy link
Member

mna commented Feb 28, 2024

Hey Jonathan,

Thanks for this! That behaviour actually predates the new Map addition as this is also how I had implemented the Selection.Map method. That's definitely worth it, I'll get that merged soon.

Martin

@mna mna merged commit 2095230 into PuerkitoBio:master Feb 29, 2024
6 checks passed
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.

None yet

2 participants