From 82f6f164a1af6557451e580dcf3197ad94e5437e Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 30 May 2023 20:23:51 -0700 Subject: InternPool: improve hashing performance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Key.PtrType is now an extern struct so that hashing it can be done by reinterpreting bytes directly. It also uses the same representation for type_pointer Tag encoding and the Key. Accessing pointer attributes now requires packed struct access, however, many operations are now a copy of a u32 rather than several independent fields. This function moves the top two most used Key variants - pointer types and pointer values - to use a single-shot hash function that branches for small keys instead of calling memcpy. As a result, perf against merge-base went from 1.17x ± 0.04 slower to 1.12x ± 0.04 slower. After the pointer value hashing was changed, total CPU instructions spent in memcpy went from 4.40% to 4.08%, and after additionally improving pointer type hashing, it further decreased to 3.72%. --- src/codegen.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/codegen.zig') diff --git a/src/codegen.zig b/src/codegen.zig index 983d895991..7fd432dceb 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -673,7 +673,7 @@ fn lowerParentPtr( mod.intern_pool.typeOf(elem.base).toType().elemType2(mod).abiSize(mod))), ), .field => |field| { - const base_type = mod.intern_pool.indexToKey(mod.intern_pool.typeOf(field.base)).ptr_type.elem_type; + const base_type = mod.intern_pool.indexToKey(mod.intern_pool.typeOf(field.base)).ptr_type.child; return lowerParentPtr( bin_file, src_loc, @@ -681,7 +681,7 @@ fn lowerParentPtr( code, debug_output, reloc_info.offset(switch (mod.intern_pool.indexToKey(base_type)) { - .ptr_type => |ptr_type| switch (ptr_type.size) { + .ptr_type => |ptr_type| switch (ptr_type.flags.size) { .One, .Many, .C => unreachable, .Slice => switch (field.index) { 0 => 0, -- cgit v1.2.3