yjh0502 / rust-s2

S2 geometry library in Rust
Apache License 2.0
74 stars 19 forks source link

Large Memory Consumption on Region Covering #42

Open KarlRunge opened 4 months ago

KarlRunge commented 4 months ago

While trying to cover a region of lat lon (Lat: -37 -> -38, Lon: 147 -> 148), While getting all the CellIds in that region. The function call seems to use approx 2.5gb of RAM, which what should be approx 200mb.

Reproduction code:

let coverer = s2::region::RegionCoverer {
    min_level: 19,
    max_level: 19,
    level_mod: 0,
    max_cells: usize::MAX,
};

let rect = s2::rect::Rect::from_degrees(
    -38.0,
    144.0,
    -37.0,
    145.0,
);
let children_cells = coverer.covering(&rect).0;
yjh0502 commented 3 months ago

I tried to reproduce the result by myself. Here's code snippet that I used to reproduce: https://gist.github.com/yjh0502/377ea1998e74abcd40a38bf7e4eab73a

I believe 200mb comes from memory usage to store output ((8b * 40040019) / (2**20) ~= 305mb). It seems covering requires more memory for calculation.