Skip to content

First benchmark.#41

Draft
ximon18 wants to merge 8 commits intonextfrom
faster-manual-deserializer-with-benchmark
Draft

First benchmark.#41
ximon18 wants to merge 8 commits intonextfrom
faster-manual-deserializer-with-benchmark

Conversation

@ximon18
Copy link
Copy Markdown
Member

@ximon18 ximon18 commented Dec 2, 2025

No description provided.

ximon18 and others added 6 commits November 19, 2025 12:05
This commit imports some draft optimization work intended for
'kmip-ttlv', with the goal of deprecating that crate entirely.  The fast
scanner and formatter defined here should provide good performance and
have a simple API, that 'src/de/mod.rs' needs to be rebased onto.
The only breaking change is to 'CryptographicUsageMask', defining it via
'bitflags' instead of 'enum-flags'.  The latter hasn't been updated in a
while and 'bitflags' is the preferred crate for this purpose.
Also expand 'impl_ttlv_serde' with struct support.
@ximon18 ximon18 requested a review from bal-e December 2, 2025 21:11
Comment thread benches/benchmark.rs Outdated
Copy link
Copy Markdown

@bal-e bal-e left a comment

Choose a reason for hiding this comment

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

Thanks for converting the test cases! Once you're done, I'll investigate the unexpected failures.

Comment thread .helix/languages.toml Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please don't add this to the repository, in case others have conflicting settings. Something like echo "*" > .helix/.gitignore will make sure it stays ignored, without even appearing in the repository's .gitignore.

Comment thread benches/benchmark.rs Outdated
Comment thread src/tests/handle_unspecified_input.rs Outdated
/// The server information response field is vendor specific and thus could contain anything.
/// We don't attempt to make sense of it, but we shouldn't fail to deserialize this kind of response either.
#[test]
#[ignore = "currently failing, investigate why"]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm fairly sure I didn't add support for this in the manual deserializer. I'll check up on this.

Comment thread benches/benchmark.rs
Comment on lines +48 to +65
fn fast(ttlv_bytes: &[u8]) {
let mut scanner = kmip_protocol::ttlv::fast_scan::FastScanner::new(ttlv_bytes).unwrap();
let req = RequestMessage::fast_scan(&mut scanner).unwrap();

assert_eq!(
req.header().protocol_version(),
&request::ProtocolVersion(ProtocolVersionMajor(1), ProtocolVersionMinor(0))
);
}

fn slow(ttlv_bytes: &[u8]) {
let req: RequestMessage = kmip_ttlv::de::from_slice(ttlv_bytes).unwrap();

assert_eq!(
req.header().protocol_version(),
&request::ProtocolVersion(ProtocolVersionMajor(1), ProtocolVersionMinor(0))
);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I just realized, Criterion provides facilities to ensure things aren't getting optimized away. If you remove the assertion and just return the parsed RequestMessage, Criterion will capture it and tell the compiler not to optimize it away.

Comment on lines -48 to -57
#[rustfmt::skip]
let use_case_request_hex = concat!(
"42007801000000904200770100000048420069010000002042006A0200000004000000010000000042006B02000000040",
// ^RequestMessage ^RequestHeader ^ProtocolVersion^ProtocolVersionMajor ^ProtocolVersionMinor
"0000000000000004200500200000004000001000000000042000D0200000004000000010000000042000F010000003842",
// ^MaximumResponseSize ^BatchCount ^BatchItem ^O
"005C050000000400000018000000004200790100000020420074050000000400000001000000004200740500000004000",
// peration ^RequestPayload ^QueryFunction::Operations ^QueryFunction::Objects
"0000200000000"
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I would recommend keeping this around. While the round-trip test is important, it doesn't guarantee that the right bytes are being produced.

Comment on lines +76 to +81
// Arya TODO: document why MaybeUninit: rationale=avoids unnecessary
// performance cost of zeroing a buffer before writing to it.
//
// Arya TODO: note the limited scope: Request deserialization but not
// response deserialization, latter wanted but former most needed for use
// by kmip2pkcs11.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

These should probably end up as GH comments on my PR instead (but I understand this is still a draft PR)

@ximon18
Copy link
Copy Markdown
Member Author

ximon18 commented Dec 3, 2025

Only the benchmark was supposed to be pushed, the rest is accidental and I will remove it.

@ximon18 ximon18 force-pushed the faster-manual-deserializer-with-benchmark branch from 576c688 to 57a0a78 Compare December 3, 2025 08:30
@bal-e bal-e force-pushed the faster-manual-deserializer branch 2 times, most recently from 82f122e to 468db23 Compare December 8, 2025 08:28
Base automatically changed from faster-manual-deserializer to next December 12, 2025 13:09
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

Successfully merging this pull request may close these issues.

2 participants