Hi,

Given the following immutable type,

  immutable Point
    x::Float64
    y::Float64
  end

the first code sinks allocations of values of that type,

  f() = Point(2.0, 3.0)

  let
    x = Array(Point, 1000000)
    @time for i = 1:length(x)
      x[i] = f()
    end
  end

  ## elapsed time: 0.004287101 seconds (0 bytes allocated)

while the second code does not sink allocations:

  let
    g() = Point(2.0, 3.0)

    let
      x = Array(Point, 1000000)
      @time for i = 1:length(x)
        x[i] = g()
      end
    end
  end

  ## elapsed time: 0.074520601 seconds (40181616 bytes allocated, 12.42% gc 
time)

Why do the calls to the local function allocate temporaries?

Peter

Reply via email to