I did a small experiment:
My chessprogram computes all attackdata @comptime into hard constant arrays, so these are baked into the exe.
Now I did a clone which creates these into a heap-created struct with attackdata @runtime.
To my surprise the heap-version is faster.
Why could that be?
Bench:
Total nodes: 18999768562 13.772s 1379.5293 Mnodes/s (1379529270) // comptimes
Total nodes: 18999768562 13.089s 1451.5786 Mnodes/s (1451578573) // heap
const Data = struct {
file_magics: [64]MagicEntry,
main_magics: [64]MagicEntry,
anti_magics: [64]MagicEntry,
pawn_attacks_white: [64]u64,
pawn_attacks_black: [64]u64,
knight_attacks: [64]u64,
king_attacks: [64]u64,
rank_attacks: [64 * 64]u64,
file_attacks: [64 * 64]u64,
diag_main_attacks: [64 * 64]u64,
diag_anti_attacks: [64 * 64]u64,
};
const MagicEntry = struct {
mask: u64,
magic: u64,
};