mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-22 10:58:57 +00:00
356c5055ad
### Purpose Remove the `lib/sha256` package, because it's no longer necessary. Go's standard library now has the same performance and is on par with `sha256-simd` since [Since Go 1.21](1a64574f42
). Therefore using `sha256-simd` has no benefits anymore. ARM already has optimized sha256 assembly code since7b8a7f8272
, `sha256-simd` published their results before that optimized assembly was implemented,f941fedda8
. The assembly looks very similar and the benchmarks in the Go commit match that of `sha256-simd`. This patch removes all of the related code of `lib/sha256` and makes `crypto/sha256` the 'default'. Benchmark of `sha256-simd` and `crypto/sha256`: <details> ``` cpu: AMD Ryzen 5 3600X 6-Core Processor │ simd.txt │ go.txt │ │ sec/op │ sec/op vs base │ Hash/8Bytes-12 63.25n ± 1% 73.38n ± 1% +16.02% (p=0.002 n=6) Hash/64Bytes-12 98.73n ± 1% 105.30n ± 1% +6.65% (p=0.002 n=6) Hash/1K-12 567.2n ± 1% 572.8n ± 1% +0.99% (p=0.002 n=6) Hash/8K-12 4.062µ ± 1% 4.062µ ± 1% ~ (p=0.396 n=6) Hash/1M-12 512.1µ ± 0% 510.6µ ± 1% ~ (p=0.485 n=6) Hash/5M-12 2.556m ± 1% 2.564m ± 0% ~ (p=0.093 n=6) Hash/10M-12 5.112m ± 0% 5.127m ± 0% ~ (p=0.093 n=6) geomean 13.82µ 14.27µ +3.28% │ simd.txt │ go.txt │ │ B/s │ B/s vs base │ Hash/8Bytes-12 120.6Mi ± 1% 104.0Mi ± 1% -13.81% (p=0.002 n=6) Hash/64Bytes-12 618.2Mi ± 1% 579.8Mi ± 1% -6.22% (p=0.002 n=6) Hash/1K-12 1.682Gi ± 1% 1.665Gi ± 1% -0.98% (p=0.002 n=6) Hash/8K-12 1.878Gi ± 1% 1.878Gi ± 1% ~ (p=0.310 n=6) Hash/1M-12 1.907Gi ± 0% 1.913Gi ± 1% ~ (p=0.485 n=6) Hash/5M-12 1.911Gi ± 1% 1.904Gi ± 0% ~ (p=0.093 n=6) Hash/10M-12 1.910Gi ± 0% 1.905Gi ± 0% ~ (p=0.093 n=6) geomean 1.066Gi 1.032Gi -3.18% ``` </details> ### Testing Compiled and tested on Linux. ### Documentation https://github.com/syncthing/docs/pull/874
127 lines
3.5 KiB
Go
127 lines
3.5 KiB
Go
// Copyright (C) 2019 The Syncthing Authors.
|
|
//
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
package build
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"regexp"
|
|
"runtime"
|
|
"sort"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
const Codename = "Gold Grasshopper"
|
|
|
|
var (
|
|
// Injected by build script
|
|
Version = "unknown-dev"
|
|
Host = "unknown"
|
|
User = "unknown"
|
|
Stamp = "0"
|
|
Tags = ""
|
|
|
|
// Set by init()
|
|
Date time.Time
|
|
IsRelease bool
|
|
IsCandidate bool
|
|
IsBeta bool
|
|
LongVersion string
|
|
Extra string
|
|
|
|
allowedVersionExp = regexp.MustCompile(`^v\d+\.\d+\.\d+(-[a-z0-9]+)*(\.\d+)*(\+\d+-g[0-9a-f]+|\+[0-9a-z]+)?(-[^\s]+)?$`)
|
|
|
|
envTags = []string{
|
|
"STGUIASSETS",
|
|
"STNORESTART",
|
|
"STNOUPGRADE",
|
|
}
|
|
)
|
|
|
|
const versionExtraAllowedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-. "
|
|
|
|
func init() {
|
|
if Version != "unknown-dev" {
|
|
// If not a generic dev build, version string should come from git describe
|
|
if !allowedVersionExp.MatchString(Version) {
|
|
log.Fatalf("Invalid version string %q;\n\tdoes not match regexp %v", Version, allowedVersionExp)
|
|
}
|
|
}
|
|
setBuildData()
|
|
}
|
|
|
|
func setBuildData() {
|
|
// Check for a clean release build. A release is something like
|
|
// "v0.1.2", with an optional suffix of letters and dot separated
|
|
// numbers like "-beta3.47". If there's more stuff, like a plus sign and
|
|
// a commit hash and so on, then it's not a release. If it has a dash in
|
|
// it, it's some sort of beta, release candidate or special build. If it
|
|
// has "-rc." in it, like "v0.14.35-rc.42", then it's a candidate build.
|
|
//
|
|
// So, every build that is not a stable release build has IsBeta = true.
|
|
// This is used to enable some extra debugging (the deadlock detector).
|
|
//
|
|
// Release candidate builds are also "betas" from this point of view and
|
|
// will have that debugging enabled. In addition, some features are
|
|
// forced for release candidates - auto upgrade, and usage reporting.
|
|
|
|
exp := regexp.MustCompile(`^v\d+\.\d+\.\d+(-[a-z]+[\d\.]+)?$`)
|
|
IsRelease = exp.MatchString(Version)
|
|
IsCandidate = strings.Contains(Version, "-rc.")
|
|
IsBeta = strings.Contains(Version, "-")
|
|
Extra = filterString(os.Getenv("STVERSIONEXTRA"), versionExtraAllowedChars)
|
|
|
|
stamp, _ := strconv.Atoi(Stamp)
|
|
Date = time.Unix(int64(stamp), 0)
|
|
LongVersion = LongVersionFor("syncthing")
|
|
}
|
|
|
|
// LongVersionFor returns the long version string for the given program name.
|
|
func LongVersionFor(program string) string {
|
|
// This string and date format is essentially part of our external API. Never change it.
|
|
date := Date.UTC().Format("2006-01-02 15:04:05 MST")
|
|
v := fmt.Sprintf(`%s %s "%s" (%s %s-%s) %s@%s %s`, program, Version, Codename, runtime.Version(), runtime.GOOS, runtime.GOARCH, User, Host, date)
|
|
|
|
if tags := TagsList(); len(tags) > 0 {
|
|
v = fmt.Sprintf("%s [%s]", v, strings.Join(tags, ", "))
|
|
}
|
|
return v
|
|
}
|
|
|
|
func TagsList() []string {
|
|
tags := strings.Split(Tags, ",")
|
|
if len(tags) == 1 && tags[0] == "" {
|
|
tags = tags[:0]
|
|
}
|
|
for _, envVar := range envTags {
|
|
if os.Getenv(envVar) != "" {
|
|
tags = append(tags, strings.ToLower(envVar))
|
|
}
|
|
}
|
|
if Extra != "" {
|
|
tags = append(tags, Extra)
|
|
}
|
|
|
|
sort.Strings(tags)
|
|
return tags
|
|
}
|
|
|
|
// filterString returns a copy of s with all characters not in allowedChars
|
|
// removed.
|
|
func filterString(s, allowedChars string) string {
|
|
var res strings.Builder
|
|
for _, c := range s {
|
|
if strings.ContainsRune(allowedChars, c) {
|
|
res.WriteRune(c)
|
|
}
|
|
}
|
|
return res.String()
|
|
}
|