Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance of encoding and decoding octet strings #85

Open
rksm opened this issue Sep 11, 2024 · 0 comments
Open

Performance of encoding and decoding octet strings #85

rksm opened this issue Sep 11, 2024 · 0 comments

Comments

@rksm
Copy link

rksm commented Sep 11, 2024

Hello! Thank you for this project! It seems to be the fastest ASN.1 implementation for Rust and is easy to use!

I don't want to report a bug but have a question regarding encoding and decoding of raw binary data with octet strings. I'm not familiar with ASN.1 and are probably holding it wrong. So this might be more a UPER related question than something asn1rs specific. Apologies :)


I have a data type defined like

AudioDataMessage ::= SEQUENCE {
    field1 INTEGER (0..65535), -- u16
    field2 INTEGER (0..255), -- u8
    field3 INTEGER (0..255), -- u8
    data OCTET STRING
}

When I profile the performance of encoding and decoding data to unaligned PER, I see some unexpected slowdowns, in particular, writing the data field.

Here is a valgrind --tool=callgrind call graph of the encoding process

hyper-asn-timing_asn_encode_small

and here of the decode:

hyper-asn-timing-asn_decode_small

The majority of the time seems to be spent at write_octect_string -> bit_string_copy_bulked and read_octet_string -> bit_string_copy_bulked. Now the majority of my data is made up of binary blobs that I need to get in and out verbatim.

I simply encode and decode my data with

let mut writer = UperWriter::default();
writer.write(data)?;
let data = writer.into_bytes_vec();
// ...
let mut reader = UperReader::from(data);
let data = reader.read::<T>();

If I understand it correctly, shifting the data such that it fits the UPER correctly is causing that. Are there any tips of how to deal with that to not incur that cost? Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant