perf(tools): drop the embedded ripgrep binaries

The rg package carried three platform binaries (14MB) inside the Go
binary and extracted the matching one to a temp file on every single
run, so a long-lived daemon left a trail of copies behind and paid the
write on each grep. Nothing depended on ripgrep's own output format.

grep now uses the Go implementation unconditionally.
This commit is contained in:
sam committed 2026-08-04 01:44:03 +10:00
1 parent bb77f88f73
commit efa7e65755
9 files changed
+12 -92

No files matched your search

+12 -4
View File
@@ -4,6 +4,10 @@
// Mutations from upstream:
// - package renamed tools -> builtin (archie-core already has an
// internal/tools package holding the registry these are registered into).
// - the embedded ripgrep binaries (upstream internal/tools/builtin/rg) were
// removed. They were 14MB of tracked binaries that were re-extracted to a
// temporary directory on every run. grepBinary now resolves rg from PATH
// and the existing pure-Go grepFallback covers its absence.
//
// Refresh by diffing against that path at a newer tau commit. Do not
// edit without recording the change above.
@@ -21,8 +25,6 @@ import (
"regexp"
"strings"
"unicode/utf8"
"github.com/samcharles93/archie-core/internal/tools/builtin/rg"
)
const (
@@ -574,9 +576,15 @@ func buildGrepArgs(p GrepParams) []string {
return args
}
// grepBinary resolves ripgrep from PATH. When it is absent the caller falls
// back to grepFallback, the pure-Go search, so this returning an error is an
// ordinary outcome rather than a failure.
//
// Upstream tau embeds ripgrep binaries for each platform and extracts one to
// a temporary directory on demand. That cost 14MB of tracked binaries and
// wrote the binary out again on every run, which is why it was removed here.
func grepBinary() (string, error) {
// Use the embedded statically-linked ripgrep binary.
return rg.Path()
return exec.LookPath("rg")
}
// hasUppercase reports whether s contains any uppercase ASCII letter.
Binary file not shown.
Binary file not shown.
Binary file not shown.
-45
View File
@@ -1,45 +0,0 @@
//go:build (darwin && amd64) || (linux && amd64) || (windows && amd64)
// Package rg embeds a statically-linked ripgrep binary and exposes a single
// entry point so the grep tool can always use authoritative rg matching.
package rg
import (
"fmt"
"os"
"path/filepath"
"sync"
)
var (
extractOnce sync.Once
extractPath string
extractErr error
)
// Path returns the filesystem path to the embedded rg binary, extracting it
// to a temporary file on first call. The caller must not remove the file.
func Path() (string, error) {
extractOnce.Do(func() {
extractPath, extractErr = extract()
})
if extractErr != nil {
return "", extractErr
}
return extractPath, nil
}
func extract() (string, error) {
dir, err := os.MkdirTemp("", "tau-rg-*")
if err != nil {
return "", fmt.Errorf("create rg temp dir: %w", err)
}
exe := filepath.Join(dir, "rg")
if isWindows {
exe += ".exe"
}
if err := os.WriteFile(exe, binary, 0o755); err != nil {
return "", fmt.Errorf("write embedded rg: %w", err)
}
return exe, nil
}
@@ -1,10 +0,0 @@
//go:build darwin && amd64
package rg
import _ "embed"
const isWindows = false
//go:embed rg-darwin-amd64
var binary []byte
@@ -1,10 +0,0 @@
//go:build linux && amd64
package rg
import _ "embed"
const isWindows = false
//go:embed rg-linux-amd64
var binary []byte
@@ -1,13 +0,0 @@
//go:build !((darwin && amd64) || (linux && amd64) || (windows && amd64))
// Package rg embeds a statically-linked ripgrep binary and exposes a single
// entry point so the grep tool can always use authoritative rg matching.
package rg
import "errors"
// Path reports that no ripgrep binary is bundled for this platform/arch.
// Callers fall back to the pure-Go grep implementation.
func Path() (string, error) {
return "", errors.New("no embedded ripgrep binary for this platform")
}
@@ -1,10 +0,0 @@
//go:build windows && amd64
package rg
import _ "embed"
const isWindows = true
//go:embed rg-windows-amd64.exe
var binary []byte