paulmach / orb

Types and utilities for working with 2d geometry in Golang
MIT License
886 stars 103 forks source link

quadtree: fix bad sort due to pointer allocation issue #115

Closed paulmach closed 1 year ago

paulmach commented 1 year ago

Fixes https://github.com/paulmach/orb/issues/112

This was due to me being clever and trying to reuse some memory, but I was not that clever...

This does hurt the bench marks a bit, but I think it's because it's doing the right thing now

benchmark                         old ns/op     new ns/op     delta
BenchmarkRandomKNearest10-10      1587          1828          +15.19%
BenchmarkRandomKNearest100-10     12826         18354         +43.10%

benchmark                         old allocs     new allocs     delta
BenchmarkRandomKNearest10-10      14             3              -78.57%
BenchmarkRandomKNearest100-10     104            3              -97.12%

benchmark                         old bytes     new bytes     delta
BenchmarkRandomKNearest10-10      472           400           -15.25%
BenchmarkRandomKNearest100-10     3432          2800          -18.41%

Many thanks to @sapiens-sapide for the clean test case in https://github.com/paulmach/orb/issues/112