Issue 1:
I find constructors taking keyword arguments are a lot slower than constructors that don't. For example,

julia> immutable PositionalArg
x::Int
PositionalArg(x::Int=1) = new(x)
end

julia> immutable KeywordArg
x::Int
KeywordArg(;x::Int=1) = new(x)
end

julia> using BenchmarkTools

julia> @benchmark PositionalArg()
BenchmarkTools.Trial:
memory estimate: 0.00 bytes
allocs estimate: 0
--------------
minimum time: 2.087 ns (0.00% GC)
median time: 2.092 ns (0.00% GC)
mean time: 2.381 ns (0.00% GC)
maximum time: 386.548 ns (0.00% GC)
--------------
samples: 10000
evals/sample: 1000
time tolerance: 5.00%
memory tolerance: 1.00%

julia> @benchmark KeywordArg()
BenchmarkTools.Trial:
memory estimate: 16.00 bytes
allocs estimate: 1
--------------
minimum time: 75.253 ns (0.00% GC)
median time: 78.912 ns (0.00% GC)
mean time: 101.540 ns (1.62% GC)
maximum time: 26.617 μs (0.00% GC)
--------------
samples: 10000
evals/sample: 970
time tolerance: 5.00%
memory tolerance: 1.00%

Such a huge difference seems to be caused by the additional allocations that constructors with keyword arguments use. However, I'm not sure if that has to be the case, because ordinary functions don't seem to be using additional allocations when taking keyword arguments:

julia> posarg(x::Int=1) = x
posarg (generic function with 2 methods)

julia> kwdarg(;x::Int=1) = x
kwdarg (generic function with 1 method)

julia> @benchmark posarg()
BenchmarkTools.Trial:
memory estimate: 0.00 bytes
allocs estimate: 0
--------------
minimum time: 1.997 ns (0.00% GC)
median time: 1.998 ns (0.00% GC)
mean time: 2.282 ns (0.00% GC)
maximum time: 95.239 ns (0.00% GC)
--------------
samples: 10000
evals/sample: 1000
time tolerance: 5.00%
memory tolerance: 1.00%

julia> @benchmark kwdarg()
BenchmarkTools.Trial:
memory estimate: 0.00 bytes
allocs estimate: 0
--------------
minimum time: 1.997 ns (0.00% GC)
median time: 1.998 ns (0.00% GC)
mean time: 2.042 ns (0.00% GC)
maximum time: 273.882 ns (0.00% GC)
--------------
samples: 10000
evals/sample: 1000
time tolerance: 5.00%
memory tolerance: 1.00%

Is this a matter that can be fixed easily, or I need to refrain from using keyword arguments in constructors?

Here is the version info:

julia> versioninfo()
Julia Version 0.6.0-dev.1636
Commit 99b6a8c* (2016-12-20 13:46 UTC)
Platform Info:
OS: macOS (x86_64-apple-darwin16.0.0)
CPU: Intel(R) Core(TM)2 Duo CPU T9900 @ 3.06GHz
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Penryn)
LAPACK: libopenblas64_
LIBM: libopenlibm
LLVM: libLLVM-3.7.1 (ORCJIT, penryn)

Issue 2:
The script that demonstrate this can be found here. Pasted below

#!/usr/bin/julia -f

f() = nothing

forward_nothing(func) = func()
forward_pos_only(func, args...) = func(args...)
forward_kw(func, args...; kws...) = func(args...; kws...)

do_sth(a, b, c) = begin
global g = a * b * c
end

macro time_forward(ex)
quote
println($(Expr(:quote, ex)))
gc()
@time for i in 1:10000000
$(esc(ex))
end
end
end

@time_forward forward_nothing(f)
@time_forward forward_pos_only(f)
@time_forward forward_kw(f)
@time_forward do_sth("a", "b", "c")
@time_forward do_sth(1, 2, 3)
@time_forward do_sth(1.2, 2.3, 3.4)
@time_forward (do_sth(1, 2, 3); do_sth(1.2, 2.3, 3.4))

The output of the script on my laptop

forward_nothing(f)
elapsed time: 0.019369954 seconds (0 bytes allocated)
forward_pos_only(f)
elapsed time: 6.2e-8 seconds (0 bytes allocated)
forward_kw(f)
elapsed time: 0.95345393 seconds (960000000 bytes allocated, 33.34% gc time)
do_sth("a","b","c")
elapsed time: 1.014413397 seconds (800000000 bytes allocated, 28.80% gc time)
do_sth(1,2,3)
elapsed time: 0.04512597 seconds (0 bytes allocated)
do_sth(1.2,2.3,3.4)
elapsed time: 0.125168819 seconds (160000000 bytes allocated, 37.53% gc time)
begin
do_sth(1,2,3)
do_sth(1.2,2.3,3.4)
end
elapsed time: 0.157331348 seconds (160000000 bytes allocated, 30.24% gc time)

There are several interesting things here,

It seems that the compiler can inline f(args...) and figure out it is useless and eliminate the loop altogether (I don't think my cpu can excute a million loops in tens of nanosecond) but it cannot do it for f(). This particular case isn't very interesting but I'm wondering if there's any missing optimizations here.

Forwarding keyword argument is very costy, even when there's nothing to be forwarded (probably a big part of it is memory allocation?). Although it would be nice to make keyword argument fast in general, the slowness of forwarding empty keyword argument means that it is very costy to support keyword arguments. One example (also how I discover this issue) is a version of invoke that supports keyword arguments. This version is ~3 times slower than the builtin invoke and a version without keyword argument support and simply forward to the builtin invoke is as fast as the builtin one.

Just for comparison, I've also included some other random functions and it seems that keyword arguments are much more expensive than global variables and is as expensive as concatenating strings. What I don't quite understand either is that why is it necessary to allocate memory when assigning floating point numbers to a global variable but not for integers? (Edit: it seems that the integer version does no allocation because of the cache of boxed value.)

Anothing thing I've noticed is that the extra keyword argument got by the functions is in a different format (Array{(Symbol, Any), 1}) from the format of argument (Array{Any, 1}) to the .env.kwsorter. Is it necessary to do this conversion? This probably won't affect the performance for empty forwarding but feels inefficient in general.

Test done on current master as of a few hours ago.

julia> versioninfo()
Julia Version 0.4.0-dev+2369
Commit bab9ec5* (2015-01-02 01:47 UTC)
Platform Info:
System: Linux (x86_64-unknown-linux-gnu)
CPU: Intel(R) Core(TM) i7-4702HQ CPU @ 2.20GHz
WORD_SIZE: 64
BLAS: libblas
LAPACK: liblapack
LIBM: libm
LLVM: libLLVM-3.3

The llvm version installed is 3.5 and I have no idea why it prints llvm-3.3....