Skip to content

Commit ec0e9c5

Browse files
isubasingheclaude
andcommitted
chore: remove xz codec from compression bench
The xz reference shelled out to the system binary; drop it to keep the harness self-contained. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: isubasinghe <isitha@pipekit.io>
1 parent e372eee commit ec0e9c5

2 files changed

Lines changed: 5 additions & 47 deletions

File tree

hack/compression-bench/codecs.go

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"encoding/json"
77
"fmt"
88
"io"
9-
"os/exec"
109

1110
"github.com/andybalholm/brotli"
1211
"github.com/klauspost/compress/zstd"
@@ -116,45 +115,11 @@ func brotliCodec(quality int) codec {
116115
}
117116
}
118117

119-
func runPipe(input []byte, name string, args ...string) ([]byte, error) {
120-
cmd := exec.Command(name, args...)
121-
cmd.Stdin = bytes.NewReader(input)
122-
var out, errBuf bytes.Buffer
123-
cmd.Stdout = &out
124-
cmd.Stderr = &errBuf
125-
if err := cmd.Run(); err != nil {
126-
return nil, fmt.Errorf("%s: %w: %s", name, err, errBuf.String())
127-
}
128-
return out.Bytes(), nil
129-
}
130-
131-
// xzCodec shells out to the system xz binary (real liblzma) so the LZMA
132-
// numbers reflect `xz -9`, not a weaker pure-Go reimplementation.
133-
func xzCodec() codec {
134-
return codec{
135-
name: "json+xz9",
136-
encode: func(nodes wfv1.Nodes) ([]byte, error) {
137-
b, err := marshalJSON(nodes)
138-
if err != nil {
139-
return nil, err
140-
}
141-
return runPipe(b, "xz", "-9", "-T1", "-c")
142-
},
143-
decode: func(b []byte) (wfv1.Nodes, error) {
144-
raw, err := runPipe(b, "xz", "-d", "-c")
145-
if err != nil {
146-
return nil, err
147-
}
148-
return unmarshalJSON(raw)
149-
},
150-
}
151-
}
152-
153118
// buildCodecs returns the codec matrix from the spec, in display order. The
154119
// first codec (json+gzip via util/file, i.e. the current packer path) is the
155120
// baseline that ratios are computed against. brotliLevels adds one codec per
156-
// quality (0-11); withXz adds the xz -9 reference codec.
157-
func buildCodecs(ctx context.Context, level zstd.EncoderLevel, jsonDict, protoDict []byte, brotliLevels []int, withXz bool) ([]codec, error) {
121+
// quality (0-11).
122+
func buildCodecs(ctx context.Context, level zstd.EncoderLevel, jsonDict, protoDict []byte, brotliLevels []int) ([]codec, error) {
158123
gzipCodec := codec{
159124
name: "json+gzip",
160125
encode: func(nodes wfv1.Nodes) ([]byte, error) {
@@ -177,12 +142,6 @@ func buildCodecs(ctx context.Context, level zstd.EncoderLevel, jsonDict, protoDi
177142
for _, q := range brotliLevels {
178143
codecs = append(codecs, brotliCodec(q))
179144
}
180-
if withXz {
181-
if _, err := exec.LookPath("xz"); err != nil {
182-
return nil, fmt.Errorf("-xz requested but no xz binary in PATH: %w", err)
183-
}
184-
codecs = append(codecs, xzCodec())
185-
}
186145
for _, c := range []struct {
187146
name string
188147
dict []byte

hack/compression-bench/main.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,15 @@ func main() {
3434
dictSize := flag.Int("dict-size", 112640, "max dictionary size in bytes (zstd default 110KiB)")
3535
zstdLevel := flag.Int("zstd-level", 3, "zstd encoder level: 1=fastest 2=default 3=better 4=best")
3636
brotliLevels := flag.String("brotli-levels", "", "comma-separated brotli qualities to include, e.g. 5,7,9,11 (empty: none)")
37-
withXz := flag.Bool("xz", false, "include the xz -9 reference codec (requires xz in PATH)")
3837
flag.Parse()
3938

40-
if err := run(*examplesDir, *scalesFlag, *specsPerScale, *seed, *dictSize, *zstdLevel, *brotliLevels, *withXz); err != nil {
39+
if err := run(*examplesDir, *scalesFlag, *specsPerScale, *seed, *dictSize, *zstdLevel, *brotliLevels); err != nil {
4140
fmt.Fprintln(os.Stderr, "error:", err)
4241
os.Exit(1)
4342
}
4443
}
4544

46-
func run(examplesDir, scalesFlag string, specsPerScale int, seed int64, dictSize, zstdLevel int, brotliLevelsFlag string, withXz bool) error {
45+
func run(examplesDir, scalesFlag string, specsPerScale int, seed int64, dictSize, zstdLevel int, brotliLevelsFlag string) error {
4746
// Error-level logger: SplitWorkflowYAMLFile and util/file log through the
4847
// context, and per-file parse noise isn't interesting here.
4948
ctx := logging.WithLogger(context.Background(), logging.NewSlogLogger(logging.Error, logging.Text))
@@ -105,7 +104,7 @@ func run(examplesDir, scalesFlag string, specsPerScale int, seed int64, dictSize
105104
}
106105
fmt.Printf("trained dictionaries: json=%dB proto=%dB\n\n", len(jsonDict), len(protoDict))
107106

108-
codecs, err := buildCodecs(ctx, level, jsonDict, protoDict, brotliLevels, withXz)
107+
codecs, err := buildCodecs(ctx, level, jsonDict, protoDict, brotliLevels)
109108
if err != nil {
110109
return err
111110
}

0 commit comments

Comments
 (0)