Artifact 25914474fa481567822d887e33369a0fbda28d2c0b9f659cefc6270cb9d9f06f:
- File
internal/manifest/log_noslog.go
— part of check-in
[2abfe81c2a]
at
2026-10-31 13:38:56
on branch spike/wasm-size
— perf(wasm): keep regexp, strings.Replacer and log/slog out of small builds
Spike for a smaller TinyGo engine (html-artifact-publisher). Behaviour on every platform is unchanged:
- repo: table names are checked with a byte loop, not a regexp, so a build that uses no other regexp leaves package regexp out (about 69 KB gzipped in the publisher's engine, with the engine's own two regexps). - fsltype: HTMLize escapes with a byte loop instead of a strings.Replacer (about 15 KB gzipped). - manifest: the package's diagnostics go through logDebug, logInfo and logWarn. By default they call log/slog as before. With the libfossil_noslog build tag they are written to stderr as plain lines and log/slog stays out (about 33 KB gzipped). Tests that assert on slog output need the default build. (user: [email protected], size: 997) [annotate] [blame] [check-ins using] [more...]
//go:build libfossil_noslog package manifest import ( "fmt" "os" "strings" ) // With libfossil_noslog the package's diagnostics are written to stderr as // plain lines, "LEVEL msg key=value ...", so log/slog stays out of the build. // It is for size-bound builds such as TinyGo WebAssembly, where slog costs // about 33 KB gzipped. Debug messages are dropped, as slog's default level // drops them. Tests that assert on slog output need the default build. func logDebug(string, ...any) {} func logInfo(msg string, args ...any) { logLine("INFO", msg, args) } func logWarn(msg string, args ...any) { logLine("WARN", msg, args) } func logLine(level, msg string, args []any) { var b strings.Builder b.WriteString(level) b.WriteByte(' ') b.WriteString(msg) for i := 0; i+1 < len(args); i += 2 { fmt.Fprintf(&b, " %v=%v", args[i], args[i+1]) } if len(args)%2 == 1 { fmt.Fprintf(&b, " !BADKEY=%v", args[len(args)-1]) } b.WriteByte('\n') _, _ = os.Stderr.WriteString(b.String()) }