Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
dynamo
Commits
9ddb3efd
Unverified
Commit
9ddb3efd
authored
Aug 14, 2025
by
jthomson04
Committed by
GitHub
Aug 14, 2025
Browse files
perf: Only compute checksums on debug builds (#2446)
Signed-off-by:
jthomson04
<
jwillthomson19@gmail.com
>
parent
3a3f5bf2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
15 deletions
+37
-15
lib/runtime/src/pipeline/network/codec/two_part.rs
lib/runtime/src/pipeline/network/codec/two_part.rs
+37
-15
No files found.
lib/runtime/src/pipeline/network/codec/two_part.rs
View file @
9ddb3efd
...
...
@@ -84,14 +84,27 @@ impl Decoder for TwoPartCodec {
// Advance the buffer past the lengths and checksum
src
.advance
(
24
);
let
bytes_to_hash
=
header_len
+
body_len
;
#[cfg(debug_assertions)]
{
// If the server sent a dummy checksum, skip it.
if
checksum
!=
0
{
let
bytes_to_hash
=
header_len
.checked_add
(
body_len
)
.ok_or
(
TwoPartCodecError
::
InvalidMessage
(
"Message exceeds max allowed length."
.to_string
(),
))
?
;
let
data_to_hash
=
&
src
[
..
bytes_to_hash
];
let
computed_checksum
=
xxh3_64
(
data_to_hash
);
// Compare checksums
if
checksum
!=
computed_checksum
{
return
Err
(
TwoPartCodecError
::
ChecksumMismatch
);
}
}
}
// Read header and body data
let
header
=
src
.split_to
(
header_len
)
.freeze
();
...
...
@@ -117,16 +130,25 @@ impl Encoder<TwoPartMessage> for TwoPartCodec {
}
}
dst
.put_u64
(
header_len
as
u64
);
dst
.put_u64
(
body_len
as
u64
);
// Only compute the checksum in debug mode.
// If we're in release mode, put a dummy value.
#[cfg(debug_assertions)]
{
// Compute checksum of the data
let
mut
data_to_hash
=
BytesMut
::
with_capacity
(
header_len
+
body_len
);
data_to_hash
.extend_from_slice
(
&
item
.header
);
data_to_hash
.extend_from_slice
(
&
item
.data
);
let
checksum
=
xxh3_64
(
&
data_to_hash
);
// Write header and body sizes and checksum
dst
.put_u64
(
header_len
as
u64
);
dst
.put_u64
(
body_len
as
u64
);
dst
.put_u64
(
checksum
);
}
#[cfg(not(debug_assertions))]
{
dst
.put_u64
(
0
);
}
// Write header and body
dst
.put_slice
(
&
item
.header
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment