-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(bincode): faster de/serialization of raw bytes (#351)
Optimize bincode to directly copy bytes instead of attempting to serialize/deserialize them as individual integers. This speeds up Entry de/serialization by 3-4x. Also adds a benchmark to serialize Entry before: ``` Benchmark Iterations Min(ns) Max(ns) Variance Mean(ns) ----------------------------------------------------------------------- serializeEntry 200000 1083 70417 191263 1367 --- deserializeEntry 200000 2250 60291 116981 2515 ``` after: ``` serializeEntry 200000 250 14959 8130 350 --- deserializeEntry 200000 666 21666 12248 784 ```
- Loading branch information
Showing
9 changed files
with
167 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
pub const std = @import("std"); | ||
pub const sig = @import("../sig.zig"); | ||
|
||
pub const Entry = sig.core.entry.Entry; | ||
pub const test_entry = sig.core.entry.test_entry; | ||
|
||
pub const BenchmarkEntry = struct { | ||
pub const min_iterations = 200_000; | ||
pub const max_iterations = 200_000; | ||
|
||
pub fn serializeEntry() !sig.time.Duration { | ||
const allocator = std.heap.c_allocator; | ||
|
||
var timer = try sig.time.Timer.start(); | ||
const actual_bytes = try sig.bincode.writeAlloc(allocator, test_entry.as_struct, .{}); | ||
defer allocator.free(actual_bytes); | ||
return timer.read(); | ||
} | ||
|
||
pub fn deserializeEntry() !sig.time.Duration { | ||
const allocator = std.heap.c_allocator; | ||
|
||
var timer = try sig.time.Timer.start(); | ||
const actual_struct = try sig.bincode.readFromSlice( | ||
allocator, | ||
Entry, | ||
&test_entry.bincode_serialized_bytes, | ||
.{}, | ||
); | ||
defer actual_struct.deinit(allocator); | ||
return timer.read(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters