Skip to content

Commit

Permalink
small encoding allocation optimisation (#24)
Browse files Browse the repository at this point in the history
* encode: small allocation optimisation

while small, it adds a performance increase of 20% for encoding
a 1Mib byte array to 100 shards.

* update gitignore
  • Loading branch information
alindima authored Nov 22, 2023
1 parent f0ab4e9 commit d8eb718
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
.DS_Store
12 changes: 5 additions & 7 deletions reed-solomon-novelpoly/src/field/inc_encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,11 @@ pub fn encode_sub_plain(bytes: &[u8], n: usize, k: usize) -> Result<Vec<Additive
// pad the incoming bytes with trailing 0s
// so we get a buffer of size `N` in `GF` symbols
let zero_bytes_to_add = n * 2 - bytes_len;
let elm_data = Vec::<Additive>::from_iter(bytes
.iter()
.copied()
.chain(std::iter::repeat(0u8).take(zero_bytes_to_add))
.tuple_windows()
.step_by(2)
.map(|(a, b)| Additive(Elt::from_be_bytes([a, b]))));
let mut elm_data = Vec::with_capacity(zero_bytes_to_add + (bytes.len() / 2));
let zeros = std::iter::repeat(&0u8).take(zero_bytes_to_add);
for (first, second) in bytes.into_iter().chain(zeros).tuples() {
elm_data.push(Additive(Elt::from_be_bytes([*first, *second])));
}

// update new data bytes with zero padded bytes
// `l` is now `GF(2^16)` symbols
Expand Down

0 comments on commit d8eb718

Please sign in to comment.