pub enum ResizeMode {
Incremental(usize),
Blocking,
}
Expand description
Resize behavior for a HashMap
.
Hash maps must resize when the underlying table becomes full, migrating all key and value pairs
to a new table. This type allows you to configure the resizing behavior when passed to
HashMapBuilder::resize_mode
.
Variants§
Incremental(usize)
Writers copy a constant number of key/value pairs to the new table before making progress.
Incremental resizes avoids latency spikes that can occur when insert operations have to resize a large table. However, they reduce parallelism during the resize and so can reduce overall throughput. Incremental resizing also means reads or write operations during an in-progress resize may have to search both the current and new table before succeeding, trading off median latency during a resize for tail latency.
This is the default resize mode, with a chunk size of 64
.
Blocking
All writes to the map must wait till the resize completes before making progress.
Blocking resizes tend to be better in terms of throughput, especially in setups with multiple writers that can perform the resize in parallel. However, they can lead to latency spikes for insert operations that have to resize large tables.
If insert latency is not a concern, such as if the keys in your map are stable, enabling blocking resizes may yield better performance.
Blocking resizing may also be a better option if you rely heavily on iteration or similar operations, as they require completing any in-progress resizes for consistency.