authorgravatar for sahnvour@pm.meSahnvour <sahnvour@pm.me> 2019-07-16 22:32:10+02:00
committergravatar for sahnvour@pm.meSahnvour <sahnvour@pm.me> 2019-08-04 12:34:37+02:00
log54255ee32e1e6c83b04c3e5f2f1dd7e8aa5e0dd7
tree884c44d1ed779aca0710dccb58529cfe86f3bf22
parent3faf5d38576616d033c343130607189eb9fe613c

autohash: force inlining of integer hashing so that the optimizer can see the fast path based on key's size which is known at comptime

otherwise it will always outline the call to hasher.update, resulting in much worse performance

1 files changed, 3 insertions(+), 1 deletions(-)

std/hash/auto_hash.zig+3-1
...@@ -21,7 +21,9 @@ pub fn autoHash(hasher: var, key: var) void {...@@ -21,7 +21,9 @@ pub fn autoHash(hasher: var, key: var) void {
21 builtin.TypeId.EnumLiteral,21 builtin.TypeId.EnumLiteral,
22 => @compileError("cannot hash this type"),22 => @compileError("cannot hash this type"),
2323
24 builtin.TypeId.Int => hasher.update(std.mem.asBytes(&key)),24 // Help the optimizer see that hashing an int is easy by inlining!
25 // TODO Check if the situation is better after #561 is resolved.
26 builtin.TypeId.Int => @inlineCall(hasher.update, std.mem.asBytes(&key)),
2527
26 builtin.TypeId.Float => |info| autoHash(hasher, @bitCast(@IntType(false, info.bits), key)),28 builtin.TypeId.Float => |info| autoHash(hasher, @bitCast(@IntType(false, info.bits), key)),
2729