starshard

Starshard 2.x vs 1.x: Usage Differences

1. Scope

This document focuses on usage-level differences and migration guidance.

2. Quick Summary

3. High-Level Differences

Area 1.x 2.x
Shard-count safety very large shard_count could cause memory pressure default MAX_SHARDS guard, plus strict constructors
Constructor strategy mostly direct constructors compatibility + capped + strict constructor paths
Dynamic rebalance not available rebalance_to, start_rebalance_online, advance_rebalance
Snapshot strategy traditional path SnapshotMode::{Clone, Cached, Cow}
Migration effort - low for default usage, incremental for advanced usage

4. Detailed Usage Changes

4.1 Constructor and Shard Safety (2.0.0)

New practical behavior in 2.x:

Recommended for external/user-driven configs:

use starshard::ShardedHashMap;
use rustc_hash::FxBuildHasher;

let map = ShardedHashMap::<String, i32>::try_with_shards_and_hasher_capped(
    4096,
    FxBuildHasher,
    8192,
)?;

Migration note:

4.2 Rebalance APIs (2.1+)

1.x has no dynamic rebalance APIs.

2.1+ adds:

use starshard::{RebalanceOptions, ShardedHashMap};

let m: ShardedHashMap<String, i32> = ShardedHashMap::new(8);
m.rebalance_to(32, RebalanceOptions::default())?;

4.3 Snapshot Mode Selection (2.2+)

2.2+ makes snapshot strategy explicit:

And adds mode-aware constructors:

use starshard::{ShardedHashMap, SnapshotMode};

let map: ShardedHashMap<String, i32> =
    ShardedHashMap::with_snapshot_mode(64, SnapshotMode::Cached);

4.4 Performance-Relevant Behavior

These are mostly transparent to callers.

5. Feature Flag Reminder

If migrating from early 1.x, re-check Cargo.toml feature selection:

[dependencies]
starshard = { version = "2.2.0", features = ["async", "rayon", "serde", "lifecycle", "advanced"] }

6. Migration Checklist

  1. Upgrade dependency to 2.x (recommended: 2.2.x).
  2. Review constructor entry points:
    • external input -> use try_with_*
    • fixed internal params -> compatibility constructors are fine
  3. Adopt rebalance APIs only if you need runtime shard transitions.
  4. Evaluate SnapshotMode::Cached / Cow for snapshot-heavy workloads.
  5. Run validation:
    • cargo test --all-features
    • workload-specific latency/throughput/memory checks

7. Compatibility Conclusion