Commit 0a8b115
committed
perf(path,io): CleanPath OS-native fast path + WriteString zero-copy fallback
Two more lifts driven by go-mlx hot-path usage tally (PathJoin/JoinPath/
Path 800+ calls, WriteString 318 calls):
* CleanPath: when ds == PathSeparator (the >99% case), delegate to
stdlib filepath.Clean — byte-level scan vs the Split/Join pipeline.
Non-OS-native separators fall through to the existing impl.
Bench impact:
CleanPath_NoChange 143.5 ns / 6 allocs → 24.1 ns / 0 allocs 6.0x
CleanPath_DotDot 179.1 ns / 6 allocs → 75.2 ns / 2 allocs 2.4x
* WriteString: when the writer exposes WriteString (strings.Builder,
bytes.Buffer, *os.File), delegate. For writers without one, swap
stdlib io.WriteString's []byte(s) copy for AsBytes(s) — safe under
the io.Writer contract (implementations must not retain or mutate
the slice past the call).
Bench impact:
WriteString_Short ~7 ns / 1 alloc → 4.97 ns / 0 allocs 1.4x
WriteString_1KB ~30 ns → 18.65 ns / 1 alloc
go-mlx hot-path audit found these were the two remaining wins; the
inference per-token path itself runs through core primitives at
near-zero alloc (Sprintf only fires on error branches that don't hit
in steady state, Env is cached, error construction is one alloc).1 parent ffb1abb commit 0a8b115
2 files changed
Lines changed: 22 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
128 | 135 | | |
129 | | - | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
130 | 144 | | |
131 | 145 | | |
132 | 146 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
158 | 162 | | |
159 | 163 | | |
160 | 164 | | |
161 | 165 | | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
162 | 169 | | |
163 | 170 | | |
164 | 171 | | |
| |||
0 commit comments