Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

tensor_chain Benchmarks

The tensor_chain crate provides a tensor-native blockchain with semantic consensus, Raft replication, 2PC distributed transactions, and sparse delta encoding.

Block Creation

ConfigurationTimePer Transaction
empty_block171 ns
block_10_txns13.4 us1.34 us
block_100_txns111 us1.11 us

Transaction Commit

OperationTimeThroughput
single_put432 us2.3K/s
multi_put_10480 us20.8K ops/s

Batch Transactions

CountTimeThroughput
10822 us12.2K/s
10021.5 ms4.7K/s
10001.6 s607/s

Consensus Validation

OperationTimeNotes
conflict_detection_pair279 nsHybrid cosine + Jaccard
cosine_similarity187 nsSparse vector
merge_pair448 nsOrthogonal merge
merge_all_10632 nsBatch merge
find_merge_order_109 usOptimal ordering

Codebook Operations

OperationTimeNotes
global_quantize_128d854 nsState validation
global_compute_residual925 nsDelta compression
global_is_valid_state1.28 usState machine check
local_quantize_128d145 nsEMA-adaptive
local_quantize_and_update177 nsWith EMA update
manager_quantize_128d1.2 usFull pipeline

Delta Vector Operations

OperationTimeImprovement
cosine_similarity_128d196 ns35% faster
add_128d975 ns44% faster
scale_128d163 ns35% faster
weighted_average_128d982 ns26% faster
overlaps_with8.4 ns35% faster
cosine_similarity_768d1.96 us10% faster
add_768d2.6 us27% faster

Chain Query Operations

OperationTimeImprovement
get_block_by_height1.19 us38% faster
get_tip1.06 us45% faster
get_genesis852 ns53% faster
height0.87 ns50% faster
tip_hash11.4 ns32% faster
history_key163 us15% faster
verify_chain_100_blocks276 us

Chain Iteration

OperationTimeImprovement
iterate_50_blocks88 us10% faster
get_blocks_range_0_2535 us27% faster

K-means Codebook Training

ConfigurationTime
100 vectors, 8 clusters123 us
1000 vectors, 16 clusters8.4 ms

Sparse Vector Performance

Conflict Detection by Sparsity Level (50 deltas, 128d)

SparsityTimeThroughputvs Dense
10% (dense)389 us3.1M pairs/s1x
50%261 us4.6M pairs/s1.5x
90%57 us21.5M pairs/s6.8x
99%23 us52.3M pairs/s16.9x

Individual Sparse Operations (vs previous dense implementation)

OperationSparse TimeImprovement
cosine_similarity16.5 ns76% faster
angular_distance28.5 ns64% faster
jaccard_index10.4 ns58% faster
euclidean_distance13.6 ns71% faster
overlapping_keys89 ns45% faster
add688 ns19% faster
weighted_average674 ns12% faster
project_orthogonal624 ns42% faster
detect_conflict_full53 ns33% faster

High Dimension Sparse Performance

DimensionCosine TimeBatch Detect (20 deltas)Improvement
128d10.3 ns8.9 us57% faster
256d19 ns9.5 us55% faster
512d41 ns17.2 us49-75% faster
768d62.5 ns24 us55-77% faster

Real Transaction Delta Sparsity Analysis

Measurement of actual delta sparsity for different transaction patterns (128d embeddings):

PatternAvg NNZSparsityEstimated Speedup
Single Key Update4.096.9%~10x
Multi-Field Update11.391.2%~3x
New Record Insert29.577.0%~1x
Counter Increment1.099.2%~10x
Bulk Migration59.553.5%~1x
Graph Edge7.094.5%~3x

Realistic Workload Mix (70% single-key, 20% multi-field, 10% other):

  • Average NNZ: 7.1 / 128 dimensions
  • Average Sparsity: 94.5%
  • Expected speedup: 3-10x for typical workloads

Analysis

  • Sparse advantage: Real transaction deltas are 90-99% sparse, providing 3-10x speedup
  • Hybrid conflict detection: Cosine + Jaccard catches both angular and structural conflicts
  • Memory savings: Sparse DeltaVector uses 8-32x less memory than dense for typical deltas
  • Network bandwidth: Sparse serialization reduces replication bandwidth by 8-10x
  • High dimension scaling: Benefits increase with dimension (768d: 4-5x faster than dense)
  • Common operations optimized: Single-key updates (most common) are 96.9% sparse

Distributed Systems Benchmarks

Raft Consensus Operations

OperationTimeThroughput
raft_node_create545 ns1.8M/sec
raft_become_leader195 ns5.1M/sec
raft_heartbeat_stats_snapshot4.2 ns238M/sec
raft_log_length3.7 ns270M/sec
raft_stats_snapshot416 ps2.4B/sec

2PC Distributed Transaction Operations

OperationTimeThroughput
lock_manager_acquire256 ns3.9M/sec
lock_manager_release139 ns7.2M/sec
lock_manager_is_locked31 ns32M/sec
coordinator_create46 ns21.7M/sec
coordinator_stats418 ps2.4B/sec
participant_create11 ns91M/sec

Gossip Protocol Operations

OperationTimeThroughput
lww_state_create4.2 ns238M/sec
lww_state_merge169 ns5.9M/sec
gossip_node_state_create16 ns62M/sec
gossip_message_serialize36 ns28M/sec
gossip_message_deserialize81 ns12M/sec

Snapshot Operations

OperationTimeThroughput
snapshot_metadata_create131 ns7.6M/sec
snapshot_metadata_serialize76 ns13M/sec
snapshot_metadata_deserialize246 ns4.1M/sec
raft_membership_config_create102 ns9.8M/sec
raft_with_store_create948 ns1.1M/sec

Membership Operations

OperationTimeThroughput
membership_manager_create526 ns1.9M/sec
membership_view152 ns6.6M/sec
membership_partition_status19 ns52M/sec
membership_node_status46 ns21.7M/sec
membership_stats_snapshot2.9 ns344M/sec
membership_peer_ids71 ns14M/sec

Deadlock Detection

OperationTimeThroughput
wait_graph_add_edge372 ns2.7M/sec
wait_graph_detect_no_cycle374 ns2.7M/sec
wait_graph_detect_with_cycle302 ns3.3M/sec
deadlock_detector_detect392 ns2.6M/sec

Distributed Systems Analysis

  • Lock operations are fast: Lock acquisition at 256ns and lock checks at 31ns support high-throughput 2PC
  • Gossip is lightweight: State creation <5ns, merges ~169ns - suitable for high-frequency protocol rounds
  • Stats access is near-free: Sub-nanosecond stats snapshots (416ps) mean monitoring adds no overhead
  • Deadlock detection is efficient: Cycle detection in ~300-400ns allows frequent checks without blocking
  • Node/manager creation is slower (500-950ns) - expected for initialization with data structures
  • Snapshot deserialization at 246ns is acceptable for fast recovery