-
-
Notifications
You must be signed in to change notification settings - Fork 823
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
fix: chunk memory leak, bug fix #491
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
@@ -182,7 +182,7 @@ func Chunk[T any, Slice ~[]T](collection Slice, size int) []Slice { | |||
if last > len(collection) { | |||
last = len(collection) | |||
} | |||
result = append(result, collection[i*size:last]) | |||
result = append(result, collection[i*size:last:last]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had never faced this notation, with the capacity apparently
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// appending to a chunk should not affect original array | ||
originalArray := []int{0, 1, 2, 3, 4, 5} | ||
result5 := Chunk(originalArray, 2) | ||
result5[0] = append(result5[0], 6) | ||
is.Equal(originalArray, []int{0, 1, 2, 3, 4, 5}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So. it's not only a fix of a possible memory leak, but also a functional fix, no?
I'm unsure why you are adding this check.no computer with me to check.
My point is that the commit message could mention a memory leak fix + bug fix, maybe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, updated the title
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
I would recommend using It consumes more memory, but it seems safer to me. |
using copy will be slower compared to current implementation:
Benchmark without using copy:
|
I will discuss it in another issue. |
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [github.com/samber/lo](https://togithub.com/samber/lo) | `v1.45.0` -> `v1.46.0` | [![age](https://developer.mend.io/api/mc/badges/age/go/github.com%2fsamber%2flo/v1.46.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/go/github.com%2fsamber%2flo/v1.46.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/go/github.com%2fsamber%2flo/v1.45.0/v1.46.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/go/github.com%2fsamber%2flo/v1.45.0/v1.46.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>samber/lo (github.com/samber/lo)</summary> ### [`v1.46.0`](https://togithub.com/samber/lo/releases/tag/v1.46.0) [Compare Source](https://togithub.com/samber/lo/compare/v1.45.0...v1.46.0) #### What's Changed - fix: chunk memory leak, bug fix by [@​mihir20](https://togithub.com/mihir20) in [https://github.com/samber/lo/pull/491](https://togithub.com/samber/lo/pull/491) - feat: add WaitForWithContext by [@​ccoVeille](https://togithub.com/ccoVeille) in [https://github.com/samber/lo/pull/480](https://togithub.com/samber/lo/pull/480) - add ForEachCondition implement by [@​Sianao](https://togithub.com/Sianao) in [https://github.com/samber/lo/pull/485](https://togithub.com/samber/lo/pull/485) #### New Contributors - [@​mihir20](https://togithub.com/mihir20) made their first contribution in [https://github.com/samber/lo/pull/491](https://togithub.com/samber/lo/pull/491) - [@​ccoVeille](https://togithub.com/ccoVeille) made their first contribution in [https://github.com/samber/lo/pull/480](https://togithub.com/samber/lo/pull/480) - [@​Sianao](https://togithub.com/Sianao) made their first contribution in [https://github.com/samber/lo/pull/485](https://togithub.com/samber/lo/pull/485) **Full Changelog**: samber/lo@v1.45.0...v1.46.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - "after 11pm every weekday,before 7am every weekday,every weekend" in timezone Europe/Brussels, Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/kairos-io/provider-kairos). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40MzEuNCIsInVwZGF0ZWRJblZlciI6IjM3LjQzMS40IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [github.com/samber/lo](https://togithub.com/samber/lo) | `v1.44.0` -> `v1.46.0` | [![age](https://developer.mend.io/api/mc/badges/age/go/github.com%2fsamber%2flo/v1.46.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/go/github.com%2fsamber%2flo/v1.46.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/go/github.com%2fsamber%2flo/v1.44.0/v1.46.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/go/github.com%2fsamber%2flo/v1.44.0/v1.46.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes <details> <summary>samber/lo (github.com/samber/lo)</summary> ### [`v1.46.0`](https://togithub.com/samber/lo/releases/tag/v1.46.0) [Compare Source](https://togithub.com/samber/lo/compare/v1.45.0...v1.46.0) #### What's Changed - fix: chunk memory leak, bug fix by [@​mihir20](https://togithub.com/mihir20) in [https://github.com/samber/lo/pull/491](https://togithub.com/samber/lo/pull/491) - feat: add WaitForWithContext by [@​ccoVeille](https://togithub.com/ccoVeille) in [https://github.com/samber/lo/pull/480](https://togithub.com/samber/lo/pull/480) - add ForEachCondition implement by [@​Sianao](https://togithub.com/Sianao) in [https://github.com/samber/lo/pull/485](https://togithub.com/samber/lo/pull/485) #### New Contributors - [@​mihir20](https://togithub.com/mihir20) made their first contribution in [https://github.com/samber/lo/pull/491](https://togithub.com/samber/lo/pull/491) - [@​ccoVeille](https://togithub.com/ccoVeille) made their first contribution in [https://github.com/samber/lo/pull/480](https://togithub.com/samber/lo/pull/480) - [@​Sianao](https://togithub.com/Sianao) made their first contribution in [https://github.com/samber/lo/pull/485](https://togithub.com/samber/lo/pull/485) **Full Changelog**: samber/lo@v1.45.0...v1.46.0 ### [`v1.45.0`](https://togithub.com/samber/lo/releases/tag/v1.45.0) [Compare Source](https://togithub.com/samber/lo/compare/v1.44.0...v1.45.0) #### What's Changed - perf: preallocate in Assign by [@​pmalek](https://togithub.com/pmalek) in [https://github.com/samber/lo/pull/484](https://togithub.com/samber/lo/pull/484) - feat: adding EarliestBy and LatestBy functions by [@​timych](https://togithub.com/timych) in [https://github.com/samber/lo/pull/489](https://togithub.com/samber/lo/pull/489) #### New Contributors - [@​pmalek](https://togithub.com/pmalek) made their first contribution in [https://github.com/samber/lo/pull/484](https://togithub.com/samber/lo/pull/484) - [@​timych](https://togithub.com/timych) made their first contribution in [https://github.com/samber/lo/pull/489](https://togithub.com/samber/lo/pull/489) **Full Changelog**: samber/lo@v1.44.0...v1.45.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - "on tuesday" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/open-telemetry/opentelemetry-collector-contrib). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40MzEuNCIsInVwZGF0ZWRJblZlciI6IjM3LjQzMS40IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiLCJyZW5vdmF0ZWJvdCJdfQ==--> --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: opentelemetrybot <107717825+opentelemetrybot@users.noreply.github.com> Co-authored-by: Yang Song <songy23@users.noreply.github.com>
raising a fix as mentioned in: #438