Give access to non-allocating combinations iterator#73
Merged
mschauer merged 1 commit intoJuliaMath:masterfrom Oct 12, 2018
Merged
Give access to non-allocating combinations iterator#73mschauer merged 1 commit intoJuliaMath:masterfrom
mschauer merged 1 commit intoJuliaMath:masterfrom
Conversation
Closed
|
why does it still allocate 😭 in each iteration |
Member
Author
|
Does it still? |
julia> function f(N)
for c in Combinations(N, 4)
end
end
f (generic function with 1 method)
julia> @benchmark f(10)
BenchmarkTools.Trial: 10000 samples with 9 evaluations.
Range (min … max): 2.305 μs … 142.252 μs ┊ GC (min … max): 0.00% … 96.89%
Time (median): 2.609 μs ┊ GC (median): 0.00%
Time (mean ± σ): 2.851 μs ± 4.948 μs ┊ GC (mean ± σ): 6.16% ± 3.49%
▃▅▅▃▁▁▅▇█▇▅▂ ▁▂▂▂ ▂
█████████████▇██▇██▇▆▆▅▅▁▄▄▃▃▃▄▃▁▄▃▁▄▆▇██████▆▅▁▅▄▅▅▄▄▁▅▆▇█ █
2.31 μs Histogram: log(frequency) by time 4.43 μs <
Memory estimate: 6.66 KiB, allocs estimate: 211.
julia> @benchmark f(20)
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
Range (min … max): 48.622 μs … 1.510 ms ┊ GC (min … max): 0.00% … 95.13%
Time (median): 53.622 μs ┊ GC (median): 0.00%
Time (mean ± σ): 58.645 μs ± 82.108 μs ┊ GC (mean ± σ): 7.96% ± 5.47%
▄▆▄▂▁ ▅█▇▅▃▁▁ ▂
██████████████▇▇▇▇▆▆▅▄▃▁▁▁▁▁▁▁▁▁▁▁▁▃▃▁▁▁▁▃▄▁▁▃▃▅▆█▇▇▅▄▃▅▇██ █
48.6 μs Histogram: log(frequency) by time 86.9 μs <
Memory estimate: 151.50 KiB, allocs estimate: 4846.notice the capital |
Member
Author
|
The iterator state is a vector or nothing, I don't know if small unions with vectors can be stack allocated. |
|
isn't the problem this line always heap allocate? comb = [c.a[si] for si in s] |
Member
Author
|
Can you check if #125 helps for your use case? |
|
yep, it does help with the above toy example. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This gives access to the non-allocating
Combinationsinternals such that e.g. a copy of the changing state can be made withSVector.Old:
New:
Actually, I do not see why it should still allocate in each iteration in
g, maybe you see something or one should sprinkle someinbounds.