Description
import std/strformat
discard parseStandardFormatSpecifier("")
is one example, but browsing generated C with --mm:refc shows many of them.
C compilers aren't necessarily reliable, nor should they be, at detecting that this is a verifiably idempotent operation, so the later calls can be removed, so it creates real runtime (profiled, even) overhead.
Example of generated duplicate nimZeroMem for that code in @mNim@slib@spure@sstrformat.nim.c:
static N_INLINE(tyObject_HSlice__1F9c6PBLtnXQNAmUXyCBSBw,
dotdot___stdZenumutils_90)(NI a, NI b) {
tyObject_HSlice__1F9c6PBLtnXQNAmUXyCBSBw result;
nimZeroMem((void *)(&result),
sizeof(tyObject_HSlice__1F9c6PBLtnXQNAmUXyCBSBw));
nimZeroMem((void *)(&result),
sizeof(tyObject_HSlice__1F9c6PBLtnXQNAmUXyCBSBw));
result.a = a;
result.b = b;
popFrame();
return result;
}
In this case, an tyObject_HSlice__1F9c6PBLtnXQNAmUXyCBSBw isn't huge, but for larger objects and/or in loops, this becomes more significant.
Nim Version
Nim Compiler Version 1.6.18 [Linux: amd64]
Compiled at 2024-03-09
Copyright (c) 2006-2023 by Andreas Rumpf
git hash: a749a8b742bd0a4272c26a65517275db4720e58a
active boot switches: -d:release
Nim Compiler Version 2.0.3 [Linux: amd64]
Compiled at 2024-03-09
Copyright (c) 2006-2023 by Andreas Rumpf
git hash: e374759f29da733f3c404718c333f5f3cb5f332d
active boot switches: -d:release
Nim Compiler Version 2.1.1 [Linux: amd64]
Compiled at 2024-03-09
Copyright (c) 2006-2024 by Andreas Rumpf
git hash: 94c599687796f4ee3872c8aa866827b9ed33f52b
active boot switches: -d:release
Current Output
static N_INLINE(tyObject_HSlice__1F9c6PBLtnXQNAmUXyCBSBw,
dotdot___stdZenumutils_90)(NI a, NI b) {
tyObject_HSlice__1F9c6PBLtnXQNAmUXyCBSBw result;
nimZeroMem((void *)(&result),
sizeof(tyObject_HSlice__1F9c6PBLtnXQNAmUXyCBSBw));
nimZeroMem((void *)(&result),
sizeof(tyObject_HSlice__1F9c6PBLtnXQNAmUXyCBSBw));
result.a = a;
result.b = b;
popFrame();
return result;
}
Expected Output
No duplicate nimZeroMem() calls
Possible Solution
No response
Additional Information
No response
Description
is one example, but browsing generated C with
--mm:refcshows many of them.C compilers aren't necessarily reliable, nor should they be, at detecting that this is a verifiably idempotent operation, so the later calls can be removed, so it creates real runtime (profiled, even) overhead.
Example of generated duplicate
nimZeroMemfor that code in@mNim@slib@spure@sstrformat.nim.c:In this case, an
tyObject_HSlice__1F9c6PBLtnXQNAmUXyCBSBwisn't huge, but for larger objects and/or in loops, this becomes more significant.Nim Version
Current Output
Expected Output
Possible Solution
No response
Additional Information
No response