Skip to content

Conversation

AhmedSoliman
Copy link
Contributor

@AhmedSoliman AhmedSoliman commented Aug 4, 2025

  • In log-server, keys have fixed lengths. This PR avoids small heap allocations when generating rocksdb keys.
  • Fixes a bug where we overshoot ths writer's buffer size to account for the entire batch although we don't need to do that.

Copy link

github-actions bot commented Aug 4, 2025

Test Results

  7 files  ±0    7 suites  ±0   3m 49s ⏱️ - 1m 8s
 54 tests ±0   53 ✅ ±0  1 💤 ±0  0 ❌ ±0 
223 runs  ±0  220 ✅ ±0  3 💤 ±0  0 ❌ ±0 

Results for commit 62b2615. ± Comparison against base commit f3e9ed3.

♻️ This comment has been updated with latest results.

let value_bytes = DataRecordEncoder::from(payload).encode_to_disk_format(buffer);
DataRecordKey::new(store_message.header.loglet_id, offset).to_binary_array();
let encoder = DataRecordEncoder::from(payload);
buffer.reserve(encoder.estimated_encode_size());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This avoid unnecessary memory ballooning since it'll try to allocate a single buffer that's big enough for all records combined although we just need one big enough for the biggest record.

@AhmedSoliman AhmedSoliman marked this pull request as ready for review August 4, 2025 14:48
Copy link
Contributor

@muhamadazmy muhamadazmy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch! LGTM and +1 for merging

let mut buf = [0u8; Self::size()];
let mut b = &mut buf[..];
KeyPrefix::new(KeyPrefixKind::DataRecord, loglet_id).encode_exclusive_upper_bound(&mut b);
(&mut b).put_u64(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the array is already initialised with 0 on allocation. in line 116, this call is not necessary imho

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's true, but it'd be an implicit assumption that future eyes would miss.

- In log-server, keys have fixed lengths. This PR avoids small heap allocations when generating rocksdb keys.
- Fixes a bug where we overshoot ths writer's buffer size to account for the entire batch although we don't need to do that.
@AhmedSoliman AhmedSoliman merged commit 34321b6 into main Aug 5, 2025
38 checks passed
@AhmedSoliman AhmedSoliman deleted the pr3624 branch August 5, 2025 14:31
@github-actions github-actions bot locked and limited conversation to collaborators Aug 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants