DeloitteOptimalReality / LightOSM.jl

A Julia package for downloading and analysing geospatial data from OpenStreetMap APIs.
https://deloitteoptimalreality.github.io/LightOSM.jl/docs
Other
48 stars 13 forks source link

Improve geometry calculation performance #22

Closed mmiller-max closed 3 years ago

mmiller-max commented 3 years ago

Changes to geometry calculations to improve performance:

Examples of performance improvement

a = GeoLocation(-33.8308, 151.223, 0.0)
b = GeoLocation(-33.8294, 151.22, 0.0)
a1 = GeoLocation(-33.8308, 151.223, 0.0)
a2 = GeoLocation(-33.8293, 151.221, 0.0)
A = [a1, a2]
b1 = GeoLocation(-33.8294, 150.22, 0.0)
b2 = GeoLocation(-33.8301, 151.22, 0.0)
B = [b1, b2]

# Before
julia> @btime heading(a, b, :degrees)
  17.625 μs (190 allocations: 9.53 KiB)
-60.67440494904522

# After
julia> @btime heading(a, b, :degrees)
  65.287 ns (0 allocations: 0 bytes)
 -60.67440494904522

# Before
julia> @btime heading(A, B, :degrees)
  18.916 μs (228 allocations: 10.22 KiB)
2-element Vector{AbstractFloat}:
  -90.18293447266345
  -133.92187793446274

# After
 julia> @btime heading(A, B, :degrees)
  165.349 ns (1 allocation: 96 bytes)
2-element Vector{Float64}:
  -90.18293447266345
  -133.92187793446274

# Before
 julia> @btime calculate_location($a, $heading_a, $dist_a)
  8.764 μs (96 allocations: 4.69 KiB)
GeoLocation
  lat: Float64 -32.945001009035984
  lon: Float64 151.40908284685628
  alt: Float64 0.0

# After
 julia> @btime calculate_location($a, $heading_a, $dist_a)
  84.936 ns (0 allocations: 0 bytes)
GeoLocation
  lat: Float64 -32.945001009035984
  lon: Float64 151.40908284685628
  alt: Float64 0.0