Repository navigation
specs-go: make Version a string literal - #1330
Conversation
Does it really matter? |
Ever so slightly 🤏🏻 |
Yeah, there's I think it's at least the parsing of the format-string that will always cause overhead, but I also have some recollection of trivial cases that stdlib probably could have a fast-path for, but didn't (which made me curious if there was some reason behind it, or just "nobody worked on improving it"). |
|
To Akihiro's point;
It's definitely not critical, but (even more so if it becomes just a string); does it hurt? Also "no" I think? I think this is part of @kolyshkin trip round code used to see "what more could we squeeze out of this", and I really enjoyed many of his discoveries. Some small, some more substantial, some I knew about, but also some that were interesting. |
62200f4 to
acc446e
Compare
There were no Go tests so far, but we are about to add one. Add test target to Makefile, and run it from CI. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
acc446e to
45d3eb7
Compare
Version is initialized during package initialization, which happens on every start of any program importing this package (for example, runc, which re-executes itself on every container start and exec). Using fmt.Sprintf for that takes about 4us and 5 allocations (2920 bytes). Remove all this, making it a plain string literal. Kept as a variable rather than a constant, since some users overwrite it, and changing it to a constant would break them. Add a test to make sure Version is in sync with the constants, and update the release checklist accordingly. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
45d3eb7 to
c9a066e
Compare
Versionis initialized during package initialization, which happens on every start of any program importing this package (for example, runc, which re-executes itself on every container start and exec).Using
fmt.Sprintffor that takes about 4µs and 5 allocations (2920 bytes). SinceVersionMajor,VersionMinor,VersionPatchandVersionDevare all constants, there is no need to computeVersionat runtime at all, so make it a plain string literal (as suggested by @thaJeztah in review).Versionis kept as a variable rather than a constant, since some users overwrite it (e.g. kata-containers), and making it a constant would break them.To make sure
Versionstays in sync with the constants, a test is added, and CI now runsgo test. The release checklist in RELEASES.md is updated accordingly.As a bonus, the package no longer imports
fmt.