diff --git a/src/function.jl b/src/function.jl
index ce26bdabfaf26a218f0c155301eff4d1265ab0fe..4b1a820901baa94f65182cd29d680a9da1a4fb59 100644
--- a/src/function.jl
+++ b/src/function.jl
@@ -115,8 +115,7 @@ myvec(x::Number) = x
 
 function interpolate!(dst::FeFunction, ::P1, expr::Function; params...)
     params = NamedTuple(params)
-    space = dst.space
-    mesh = space.mesh
+    mesh = dst.space.mesh
     for cell in cells(mesh)
 	for f in params
 	    bind!(f, cell)
@@ -130,8 +129,9 @@ function interpolate!(dst::FeFunction, ::P1, expr::Function; params...)
 
 	    opvalues = map(f -> evaluate(f, xloc), params)
 
-	    gdofs = space.dofmap[:, eldof, cell]
-	    dst.data[gdofs] .= myvec(expr(x; opvalues...))
+            res = myvec(expr(x; opvalues...))
+	    gdofs = dst.space.dofmap[:, eldof, cell]
+	    @inbounds dst.data[gdofs] .= res
 	end
     end
 end
diff --git a/src/image.jl b/src/image.jl
index a5449d2e2969b82537b4e3e36108941e2ace6a34..8a84e93a78501b4fc1fffd8004d955220e78d494 100644
--- a/src/image.jl
+++ b/src/image.jl
@@ -166,9 +166,13 @@ function project_l2_lagrange!(u::FeFunction, img::AbstractArray)
     a(xloc, u, du, v, dv; f) = dot(u, v)
     l(xloc, v, dv; f) = dot(f, v)
 
-    I = Float64[]
-    J = Float64[]
+    I = Int[]
+    J = Int[]
     V = Float64[]
+    n = length(img) * nrdims * nldofs * nrdims * nldofs
+    sizehint!(I, n)
+    sizehint!(J, n)
+    sizehint!(V, n)
     b = zeros(ndofs(space))
 
     # mesh cells
diff --git a/src/operator.jl b/src/operator.jl
index 40f3d669a4e40b8280feb1fa9f1c2a7d89a1f3ce..153ea67429cdac47e251a30d3a12e7f8db7c3ce0 100644
--- a/src/operator.jl
+++ b/src/operator.jl
@@ -68,9 +68,9 @@ function assemble(space::FeSpace, a, l; params...)
 
     n = ncells(mesh) * size(qx, 2) *
         nrdims * nldofs * nrdims * nldofs
-    I = zeros(n)
-    J = zeros(n)
-    V = zeros(n)
+    I = Vector{Int}(undef, n)
+    J = Vector{Int}(undef, n)
+    V = Vector{Float64}(undef, n)
     spidx = 0
     b = zeros(ndofs(space))
     gdof = LinearIndices((nrdims, ndofs(space)))