encode() is O(n^2)
mikhailOK opened this issue · comments
mikhailOK commented
for &val in input.clone() {
let mut carry = val as usize;
for byte in &mut output[..] {
carry += (*byte as usize) << 8;
*byte = (carry % 58) as u8;
carry /= 58;
}
while carry > 0 {
output.push((carry % 58) as u8);
carry /= 58;
}
}
This is insanely slow on large inputs
Nemo157 commented
I would highly recommend not using base58 for large inputs in any case, because the encoding maps each decoded byte to an irrational number of encoded bits it's impossible to stream the data in chunks, you must encode/decode the entire input before you can get the first byte. If you're transferring a large amount of data the upsides of base58 vs base64 don't really apply, and the latter has an exact mapping from 3 decoded bytes to 4 encoded bytes that allows streaming/chunked encoding/decoding.