Are calls to no-op functions passed as arguments always compiled away?

As a word of warning, there is still something broken with singletons on 0.7 master. See https://github.com/JuliaLang/julia/issues/25983.

using BenchmarkTools;
f(x)=x;

@code_native f(nothing)
	.text
; Function f {
; Location: REPL[2]:1
	movq	%rsi, -8(%rsp)
	movabsq	$139684048367624, %rax  # imm = 0x7F0ABA157008
	retq
;}

x=fill(nothing, 1000); y=copy(x); sizeof(x)
0

@btime $y .= f.($x);
30.457 ��s (489 allocations: 7.64 KiB)

@btime $y .= identity.($x);
15.317 ns (0 allocations: 0 bytes)

If you have no missing data or don’t care about speed in the next couple of weeks until this gets fixed (not by me, I don’t dare touch codegen), then you have no problem; but this issue makes some benchmarks misleading in the meantime.

edit: Fixed now in https://github.com/JuliaLang/julia/pull/26322. Merci to @kristoffer.carlsson and vtjnash!

2 Likes