feat: convert directly between C and Go arrays#85
feat: convert directly between C and Go arrays#85jogly merged 4 commits intouber:masterfrom justinhwang:justinhwang/unsafe
Conversation
|
@jogly how do you feel about this one? The optimization wasn't as significant as I thought it would be |
Pull Request Test Coverage Report for Build 15497052950Details
💛 - Coveralls |
|
These benchmarks are kinda meh anyways as they call the function on the same input over and over enabling a lot of cache behavior. Would be curious the results on randomized lat/lngs. |
|
Or testing The benchmark does show that this change cuts the temporary memory allocation exactly in half to only very slightly above the memory needed to store the cells (down from 5.38KB to 2.69KB), so that does still feel like a solid win on memory overhead, which could be proven with a monstrous polygon that spits out at least tens of thousands of cells? At a large enough size the extra But basically I wouldn't reject this PR because a server working with a lot of data simultaneously could be under a lot of memory pressure that it doesn't have to. I think it's great. :) |
Yeah there's a preexisting benchmark wherein we test with 15 resolution which was timing out - let me retry that with a lower resolution and then see what the benchmark differences are. func BenchmarkPolyfill(b *testing.B) {
for n := 0; n < b.N; n++ {
cells, _ = PolygonToCells(validGeoPolygonHoles, 15)
}
} |
Not sure I was thinking of that properly, a finer resolution would mean more |
|
I read this PR after I made this comment https://github.com/uber/h3-go/pull/84/files?w=1#r2132501753 haha. Because you're calling |
|
@jogly I couldn't get the have you had any success running that benchmark? |
Ran a couple tests and 15 is definitely too fine of a resolution, it requires 9GB of contiguous RAM without this change. 13 is a good number for the polygon being tested, and definitely shows the memory required is halved. I think the polygon being passed to this benchmark changed for a test a while back, and we never ran the benchmarks after. I also added a benchmark for your last PR and this changes halves that memory requirement as well, as expected. Great optimization! |


Save a few allocations by converting directly between C and Go arrays.
The delta here though is about even though.