Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
syscall: simplify and optimize environment block creation on Windows
createEnvBlock currently allocates multiple times: at least one to convert the slice of strings into a NULL separated slice of bytes, and then again to encode it as UTF-16. The logic to do so is also quite complex. This CL simplifies the logic by allocating only once by encoding the slice of strings into UTF-16 directly using utf16.AppendRune. goos: windows goarch: amd64 pkg: syscall cpu: Intel(R) Core(TM) i7-10850H CPU @ 2.70GHz │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ CreateEnvBlock-12 37.92µ ± 24% 21.36µ ± 8% -43.66% (p=0.000 n=10) │ old.txt │ new.txt │ │ B/op │ B/op vs base │ CreateEnvBlock-12 109.12Ki ± 0% 26.62Ki ± 0% -75.60% (p=0.000 n=10) │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ CreateEnvBlock-12 4.000 ± 0% 1.000 ± 0% -75.00% (p=0.000 n=10) Change-Id: If35f62c3926b486d5253a9ae23a33b979b2f02c2 Reviewed-on: https://go-review.googlesource.com/c/go/+/531355 Reviewed-by: Bryan Mills <[email protected]> Run-TryBot: Quim Muntal <[email protected]> TryBot-Result: Gopher Robot <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Than McIntosh <[email protected]>
- Loading branch information