From c002d9fa92732ff684c81a687d3380b5a794e7b6 Mon Sep 17 00:00:00 2001 From: Yorhel Date: Wed, 11 Jan 2023 10:39:33 +0100 Subject: [PATCH] Work around a Zig ReleaseSafe mode performance regression With a little help from IRC: Ayo: its probaly stupidly copying that array to the stack to do the safety check, pretty sure there's an open issue on this still you may be able to work around the compiler's stupidity by using a pointer to the array or slice or something ifreund: Yup, (&self.rdbuf)[self.rdoff] does the trick, thanks. no problem! should get fixed eventually --- src/scan.zig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/scan.zig b/src/scan.zig index 5da6a6e..c6bf37b 100644 --- a/src/scan.zig +++ b/src/scan.zig @@ -615,7 +615,10 @@ const Import = struct { return; } } - self.ch = self.rdbuf[self.rdoff]; + // Zig 0.10 copies the entire array to the stack in ReleaseSafe mode, + // work around that bug by indexing into a pointer to the array + // instead. + self.ch = (&self.rdbuf)[self.rdoff]; self.rdoff += 1; self.byte += 1; }