Skip to content

Commit

Permalink
Fix large allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
orso82 committed Sep 21, 2022
1 parent 4dcc4c4 commit ec07e3d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/coil_currents.jl
Original file line number Diff line number Diff line change
Expand Up @@ -601,18 +601,18 @@ function halfhull(points::Vector{Point})
halfhull = points[1:2]
for p in points[3:end]
push!(halfhull, p)
while length(halfhull) > 2 && !isrightturn(halfhull[end-2:end]...)
while length(halfhull) > 2 && !isrightturn(halfhull[end-2], halfhull[end-1], halfhull[end])
deleteat!(halfhull, length(halfhull) - 1)
end
end
return halfhull
end

function grahamscan(points::Vector{Point})
sorted = sort(points)
upperhull = halfhull(sorted)
lowerhull = halfhull(reverse(sorted))
return Point[upperhull..., lowerhull[2:end-1]...]
sort!(points)
upperhull = halfhull(points)
lowerhull = halfhull(reverse!(points))
return Point[upperhull; lowerhull[2:end-1]]
end

function convex_hull(xy_points::Vector{Point}; closed_polygon::Bool)
Expand Down

5 comments on commit ec07e3d

@bclyons12
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@orso82 Don't forget @views for things like lowerhull[2:end-1]

@orso82
Copy link
Member Author

@orso82 orso82 commented on ec07e3d Sep 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I (weirdly) saw higher allocations when I did that :(

@bclyons12
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll look into it

@orso82
Copy link
Member Author

@orso82 orso82 commented on ec07e3d Sep 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One super interesting thing is that if you remove [2:end-1] you get the wrong result but the calculation speeds up substantially!

@bclyons12
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I (weirdly) saw higher allocations when I did that :(

@orso82 Part of the trouble is the FUSE.warmup() gives me variable amounts of allocation if I run it repeatedly. I don't understand that at all.

Please sign in to comment.