mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-17 09:16:11 +03:00
perf(styles): greatly improve style.hash performance
By switching to one-shot hashing of the raw bytes of the struct with XxHash3 instead of using `autoHash` with Wyhash, a performance gain of around 20% can be observed in DOOM-fire-zig.
This commit is contained in:
@ -8,8 +8,7 @@ const Offset = size.Offset;
|
|||||||
const OffsetBuf = size.OffsetBuf;
|
const OffsetBuf = size.OffsetBuf;
|
||||||
const RefCountedSet = @import("ref_counted_set.zig").RefCountedSet;
|
const RefCountedSet = @import("ref_counted_set.zig").RefCountedSet;
|
||||||
|
|
||||||
const Wyhash = std.hash.Wyhash;
|
const XxHash3 = std.hash.XxHash3;
|
||||||
const autoHash = std.hash.autoHash;
|
|
||||||
|
|
||||||
/// The unique identifier for a style. This is at most the number of cells
|
/// The unique identifier for a style. This is at most the number of cells
|
||||||
/// that can fit into a terminal page.
|
/// that can fit into a terminal page.
|
||||||
@ -230,10 +229,13 @@ pub const Style = struct {
|
|||||||
_ = try writer.write(" }");
|
_ = try writer.write(" }");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Hash the raw bytes of the struct with XxHash3
|
||||||
|
///
|
||||||
|
/// NOTE: Because the struct does not have a guaranteed in-memory layout
|
||||||
|
/// this hash is NOT suitable for serialization. If used for a hash
|
||||||
|
/// table that is then serialized, it MUST be re-hashed when read.
|
||||||
pub fn hash(self: *const Style) u64 {
|
pub fn hash(self: *const Style) u64 {
|
||||||
var hasher = Wyhash.init(0);
|
return XxHash3.hash(0, @as(*const [@sizeOf(Style)]u8, @ptrCast(self)));
|
||||||
autoHash(&hasher, self.*);
|
|
||||||
return hasher.final();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
test {
|
test {
|
||||||
|
Reference in New Issue
Block a user