Skip to main content

Module pool

Module pool 

Source
Expand description

Object pooling for geometry types to reduce allocations

This module provides thread-local object pools for frequently allocated geometry types (Point, LineString, Polygon). Object pooling can significantly reduce allocation overhead in batch spatial operations.

§Performance Benefits

When performing many spatial operations in sequence, object pooling can:

  • Reduce allocations by 2-3x for batch operations
  • Decrease GC pressure and memory fragmentation
  • Improve cache locality for frequently reused objects

§Thread Safety

All pools are thread-local, eliminating synchronization overhead. Each thread maintains its own independent pools.

§Usage Example

use oxigdal_algorithms::vector::{Point, buffer_point_pooled, BufferOptions};

let point = Point::new(0.0, 0.0);
let options = BufferOptions::default();

// Get a pooled polygon - automatically returned to pool when guard drops
let buffered = buffer_point_pooled(&point, 10.0, &options)?;
// Use the buffered geometry...
// Automatically returned to pool here

Structs§

Pool
Generic object pool for reusable objects
PoolGuard
RAII guard that returns an object to the pool when dropped
PoolStats
Gets statistics about pool usage for the current thread

Functions§

clear_all_pools
Clears all thread-local pools
get_pool_stats
Returns statistics about current pool usage
get_pooled_coordinate_vec
Gets a Vec<Coordinate> from the thread-local pool
get_pooled_linestring
Gets a LineString from the thread-local pool
get_pooled_point
Gets a Point from the thread-local pool
get_pooled_polygon
Gets a Polygon from the thread-local pool