Skip to content

Commit

Permalink
use cos.Builder (micro-optimizations)
Browse files Browse the repository at this point in the history
* use for scrub logging
* revert cos.BytePack change (prev. commit)

Signed-off-by: Alex Aizman <[email protected]>
  • Loading branch information
alex-aizman committed Jan 3, 2025
1 parent 1226101 commit 6740803
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 12 deletions.
36 changes: 31 additions & 5 deletions cmd/cli/cli/scrub.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@ import (

// [TODO]
// - `progress` usability (when waiting > refresh-time)
// - micro-opt strings.Builder, here and elsewhere
// - add options:
// --cached
// --locally-misplaced
// --checksum
// --fix (***)
// - async execution, with --wait option
// - speed-up `ls` via multiple workers (***)
// - reuse strings.Builder buf, here and elsewhere

type (
_log struct {
Expand Down Expand Up @@ -408,6 +406,9 @@ const (
)

func (scr *scrBp) log(parent *scrCtx, en *cmn.LsoEnt, i int) {
const (
maxline = 256
)
log := &parent.logs[i]
if parent._many {
log.mu.Lock()
Expand All @@ -417,10 +418,12 @@ func (scr *scrBp) log(parent *scrCtx, en *cmn.LsoEnt, i int) {
fmt.Fprintln(log.fh, strings.Repeat("=", len(logTitle)))
}

var sb strings.Builder
sb.Grow(256)
sb := &scr.Line
sb.Reset(maxline)
sb.WriteByte('"')
sb.WriteString(scr.Bck.Cname(en.Name))

scr.cname(en.Name)

sb.WriteString(delim)
sb.WriteString(strconv.FormatInt(en.Size, 10))
sb.WriteString(delim)
Expand All @@ -430,11 +433,34 @@ func (scr *scrBp) log(parent *scrCtx, en *cmn.LsoEnt, i int) {
sb.WriteByte('"')
fmt.Fprintln(log.fh, sb.String())
log.cnt++

if parent._many {
log.mu.Unlock()
}
}

// NOTE: bck.Cname() copy-paste tradeoff
func (scr *scrBp) cname(objname string) {
var (
sb = &scr.Line
b = &scr.Bck
)
sb.WriteString(apc.ToScheme(b.Provider))
sb.WriteString(apc.BckProviderSeparator)

if b.Ns.IsGlobal() {
sb.WriteString(b.Name)
} else {
sb.WriteString(b.Ns.String())
sb.WriteByte('/')
sb.WriteString(b.Name)
}
if objname != "" {
sb.WriteByte(filepath.Separator)
sb.WriteString(objname)
}
}

func (scr *scrBp) toSB(sb *strings.Builder, listed int64) {
sb.WriteString(scr.Bck.Cname(scr.Prefix))
sb.WriteString(": scrubbed ")
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/NVIDIA/aistore/cmd/cli
go 1.23.2

require (
github.com/NVIDIA/aistore v1.3.26-0.20250102225534-6d20d7a39c75
github.com/NVIDIA/aistore v1.3.26-0.20250103172715-122610167d87
github.com/fatih/color v1.18.0
github.com/json-iterator/go v1.1.12
github.com/onsi/ginkgo/v2 v2.21.0
Expand Down
4 changes: 2 additions & 2 deletions cmd/cli/go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
code.cloudfoundry.org/bytefmt v0.0.0-20190710193110-1eb035ffe2b6/go.mod h1:wN/zk7mhREp/oviagqUXY3EwuHhWyOvAdsn5Y4CzOrc=
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/NVIDIA/aistore v1.3.26-0.20250102225534-6d20d7a39c75 h1:i11/eNAF995yrz7z0dmsXbo4kVp3uejJkZZEobg5zG8=
github.com/NVIDIA/aistore v1.3.26-0.20250102225534-6d20d7a39c75/go.mod h1:mjhY9OGIZULaC79+iRfzEUvUZw7aIWklJ8um321QVpw=
github.com/NVIDIA/aistore v1.3.26-0.20250103172715-122610167d87 h1:OfnV/PIBYwuoQoAMnkVkp4QrCJ8ljVt34Mf6CrsSJy0=
github.com/NVIDIA/aistore v1.3.26-0.20250103172715-122610167d87/go.mod h1:mjhY9OGIZULaC79+iRfzEUvUZw7aIWklJ8um321QVpw=
github.com/OneOfOne/xxhash v1.2.8 h1:31czK/TI9sNkxIKfaUfGlU47BAxQ0ztGgd9vPyqimf8=
github.com/OneOfOne/xxhash v1.2.8/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdIIOT9Um7Q=
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
Expand Down
2 changes: 2 additions & 0 deletions cmd/cli/teb/scrub.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strconv"

"github.com/NVIDIA/aistore/cmn"
"github.com/NVIDIA/aistore/cmn/cos"
"github.com/NVIDIA/aistore/cmn/debug"
)

Expand Down Expand Up @@ -50,6 +51,7 @@ type (
Bck cmn.Bck
Prefix string
Stats [ScrNumStats]CntSiz
Line cos.Builder
}
ScrubHelper struct {
All []*ScrBp
Expand Down
2 changes: 1 addition & 1 deletion cmd/ishard/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/NVIDIA/aistore/cmd/ishard
go 1.23.2

require (
github.com/NVIDIA/aistore v1.3.26-0.20250102225534-6d20d7a39c75
github.com/NVIDIA/aistore v1.3.26-0.20250103172715-122610167d87
github.com/json-iterator/go v1.1.12
github.com/vbauerster/mpb/v4 v4.12.2
)
Expand Down
4 changes: 2 additions & 2 deletions cmd/ishard/go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
code.cloudfoundry.org/bytefmt v0.0.0-20190710193110-1eb035ffe2b6/go.mod h1:wN/zk7mhREp/oviagqUXY3EwuHhWyOvAdsn5Y4CzOrc=
github.com/NVIDIA/aistore v1.3.26-0.20250102225534-6d20d7a39c75 h1:i11/eNAF995yrz7z0dmsXbo4kVp3uejJkZZEobg5zG8=
github.com/NVIDIA/aistore v1.3.26-0.20250102225534-6d20d7a39c75/go.mod h1:mjhY9OGIZULaC79+iRfzEUvUZw7aIWklJ8um321QVpw=
github.com/NVIDIA/aistore v1.3.26-0.20250103172715-122610167d87 h1:OfnV/PIBYwuoQoAMnkVkp4QrCJ8ljVt34Mf6CrsSJy0=
github.com/NVIDIA/aistore v1.3.26-0.20250103172715-122610167d87/go.mod h1:mjhY9OGIZULaC79+iRfzEUvUZw7aIWklJ8um321QVpw=
github.com/OneOfOne/xxhash v1.2.8 h1:31czK/TI9sNkxIKfaUfGlU47BAxQ0ztGgd9vPyqimf8=
github.com/OneOfOne/xxhash v1.2.8/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdIIOT9Um7Q=
github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM=
Expand Down
2 changes: 1 addition & 1 deletion cmn/cos/bytepack.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (br *ByteUnpack) ReadString() (string, error) {
if err != nil {
return "", err
}
return UnsafeS(bytes), nil
return string(bytes), nil // NOTE: dsort (cannot unsafe)
}

func (br *ByteUnpack) ReadAny(st Unpacker) error {
Expand Down
2 changes: 2 additions & 0 deletions cmn/cos/sbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
// - reusable, single-threaded, best-effort, and once-allocated
// motivation:
// - to optimally replace `strings.Builder` when applicable
// TODO:
// - use elsewhere (currently, scrub only)

type Builder struct {
buf []byte
Expand Down

0 comments on commit 6740803

Please sign in to comment.