tailscale/version
Brad Fitzpatrick 006d7e180e version: use debug.ReadBuildInfo in CmdName on non-Windows
CmdName was re-opening the running executable and scanning it in
64KiB chunks for the Go modinfo markers on every call. The same
modinfo is already parsed at startup and exposed via
runtime/debug.ReadBuildInfo, so prefer that on non-Windows. Windows
still takes the scanning path because its GUI-binary override keys
off the on-disk executable name.

benchstat of BenchmarkCmdName (Linux, before vs after):

    goos: linux
    goarch: amd64
    pkg: tailscale.com/version
    cpu: Intel(R) Xeon(R) 6975P-C
               │  /tmp/old.txt  │            /tmp/new.txt             │
               │     sec/op     │   sec/op     vs base                │
    CmdName-16   556045.5n ± 1%   825.6n ± 1%  -99.85% (p=0.000 n=10)

               │ /tmp/old.txt  │             /tmp/new.txt             │
               │     B/op      │     B/op      vs base                │
    CmdName-16   64.587Ki ± 0%   1.156Ki ± 0%  -98.21% (p=0.000 n=10)

               │ /tmp/old.txt │            /tmp/new.txt            │
               │  allocs/op   │ allocs/op   vs base                │
    CmdName-16     8.000 ± 0%   7.000 ± 0%  -12.50% (p=0.000 n=10)

Fixes #19486

Change-Id: I925c5e28b64815a602459beb6c8dab8779339a6c
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2026-04-24 09:48:11 -07:00
..
distro all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
mkversion go.toolchain.branch: switch to Go 1.26 2026-03-04 21:57:05 -08:00
.gitignore version: greatly simplify redo nonsense, now that we use VERSION. 2020-11-02 19:54:44 -08:00
cmdname_ios.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
cmdname.go version: use debug.ReadBuildInfo in CmdName on non-Windows 2026-04-24 09:48:11 -07:00
cmp_test.go version: parse Void Linux version strings 2026-04-02 09:39:03 +01:00
cmp.go version: parse Void Linux version strings 2026-04-02 09:39:03 +01:00
exename.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
export_test.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
modinfo_test.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
print.go version: show tailscale/go toolchain git hash in version output 2026-04-13 15:20:56 -07:00
prop.go version: show tailscale/go toolchain git hash in version output 2026-04-13 15:20:56 -07:00
race_off.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
race.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
version_checkformat.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
version_internal_test.go version: show tailscale/go toolchain git hash in version output 2026-04-13 15:20:56 -07:00
version_not_tsgo.go go.toolchain.rev, version: bump Tailscale Go, add IsTailscaleGo 2026-04-01 09:40:59 -07:00
version_test.go version: use debug.ReadBuildInfo in CmdName on non-Windows 2026-04-24 09:48:11 -07:00
version_tsgo.go go.toolchain.rev, version: bump Tailscale Go, add IsTailscaleGo 2026-04-01 09:40:59 -07:00
version.go version: show tailscale/go toolchain git hash in version output 2026-04-13 15:20:56 -07:00