Work around a Zig ReleaseSafe mode performance regression

With a little help from IRC:

<ifreund> 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
<ifreund> you may be able to work around the compiler's stupidity by using a
          pointer to the array or slice or something
<Ayo> ifreund: Yup, (&self.rdbuf)[self.rdoff] does the trick, thanks.
<ifreund> no problem! should get fixed eventually
This commit is contained in:
Yorhel 2023-01-11 10:39:33 +01:00
parent cebaaf0972
commit c002d9fa92

View file

@ -615,7 +615,10 @@ const Import = struct {
return; 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.rdoff += 1;
self.byte += 1; self.byte += 1;
} }