Skip to content
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

Frep evaluations shouldn't allocate. #2

Closed
sjkelly opened this issue Apr 12, 2015 · 1 comment
Closed

Frep evaluations shouldn't allocate. #2

sjkelly opened this issue Apr 12, 2015 · 1 comment

Comments

@sjkelly
Copy link
Member

sjkelly commented Apr 12, 2015

jb/tupleoverhaul doesn't seem to get rid of the allocations during FRep eval. There are some deeper design issues here:

julia> u = union(Sphere(2, (2,3,4)), Sphere(4, (4,5,6)), Sphere(5, (7,8,9)))
Descartes.CSGUnion{3,Int64}(Descartes.Sphere{3,Int64}(2,(2,3,4)),Descartes.CSGUnion{3,Int64}(Descartes.Sphere{3,Int64}(4,(4,5,6)),Descartes.Sphere{3,Int64}(5,(7,8,9))))

julia> a = FRep(u)
Descartes.FRep{3,Int64}(Descartes.CSGUnion{3,Int64}(Descartes.Sphere{3,Int64}(2,(2,3,4)),Descartes.CSGUnion{3,Int64}(Descartes.Sphere{3,Int64}(4,(4,5,6)),Descartes.Sphere{3,Int64}(5,(7,8,9)))),csgunion_frep)

julia> @code_lowered a.func(1,2,3)
1-element Array{Any,1}:
 :($(Expr(:lambda, Any[:x,:y,:z], Any[Any[],Any[Any[:x,Any,0],Any[:y,Any,0],Any[:z,Any,0]],Any[Any[:u,Descartes.CSGUnion{3,Int64},1]],0], :(begin  # /home/steve/.julia/v0.4/Descartes/src/frep.jl, line 15:
        return min((FRep((top(getfield))(u,:left)::Any)::Any)(x,y,z)::Any,(FRep((top(getfield))(u,:right)::Any)::Any)(x,y,z)::Any)::Any
    end::Any))))
@sjkelly sjkelly changed the title test with jb/tupleoverhaul Frep evaluations shouldn't allocate. Apr 12, 2015
@sjkelly
Copy link
Member Author

sjkelly commented Apr 12, 2015

More atomic case:

 julia> b = FRep(Sphere(4, (1,2,3)))
Descartes.FRep{3,Int64}(Descartes.Sphere{3,Int64}(4,(1,2,3)),sphere_frep)

julia> @code_lowered b.func(1,2,3)
1-element Array{Any,1}:
 :($(Expr(:lambda, Any[:x,:y,:z], Any[Any[],Any[Any[:x,Any,0],Any[:y,Any,0],Any[:z,Any,0]],Any[Any[:s,Descartes.Sphere{3,Int64},1]],0], :(begin  # /home/steve/.julia/v0.4/Descartes/src/frep.jl, line 7:
        return sqrt((x - getindex((top(getfield))(s,:location)::Any,1)::Any)::Any ^ 2::Any + (y - getindex((top(getfield))(s,:location)::Any,2)::Any)::Any ^ 2::Any + (z - getindex((top(getfield))(s,:location)::Any,3)::Any)::Any ^ 2::Any::Any)::Any - (top(getfield))(s,:radius)::Any::Any
    end::Any))))

So it looks like closures blow at type inference.

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

No branches or pull requests

1 participant