Skip to content

add in method #646

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

Merged
merged 1 commit into from
Aug 9, 2019
Merged

add in method #646

merged 1 commit into from
Aug 9, 2019

Conversation

stev47
Copy link
Contributor

@stev47 stev47 commented Aug 9, 2019

This change makes in unroll the loop (compared to Base.in) and is
significantly faster.

This change makes `in` unroll the loop (compared to `Base.in`) and is
significantly faster.
@coveralls
Copy link

coveralls commented Aug 9, 2019

Coverage Status

Coverage increased (+0.007%) to 81.688% when pulling 50d62fe on stev47:add-in into 41728ad on JuliaArrays:master.

@c42f
Copy link
Member

c42f commented Aug 9, 2019

Looks good to me, the generated code is much better for numeric types. It's much faster for short vectors and still a lot better for static arrays of length 16:

julia> f(x) = x in (1,3,2,5,6,7,8,10,11,12,13,70,80,81,82,16)
f (generic function with 1 method)

julia> g(x) = x in SVector(1,3,2,5,6,7,8,10,11,12,13,70,80,81,82,16)
g (generic function with 1 method)

# Wrap in mapreduce to prevent optimizer from removing `f` entirely (??)
julia> @btime mapreduce(f, |, $(rand(Int, 1000)))
  6.086 μs (0 allocations: 0 bytes)
false

julia> @btime mapreduce(g, |, $(rand(Int, 1000)))
  1.276 μs (0 allocations: 0 bytes)
false

Side note: here's an entertaining optimization opportunity exposed by this PR:

julia> g(x) = x in SVector((1,2,3,4))
g (generic function with 1 method)

julia> @code_native debuginfo=:none g(1)
	.text
	addq	$-1, %rdi
	cmpq	$4, %rdi
	setb	%al
	retq
	nopl	(%rax)

@c42f c42f merged commit 9ffa695 into JuliaArrays:master Aug 9, 2019
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.

3 participants