Commit d9522dc
committed
perf(data,embed,log): drop allocs across read paths + log formatter
Three lifts found by running the full bench against v0.10.0 and looking
properly at what's still bleeding, not just one pattern.
* Data.resolve — replace SplitN("/") with Index + string-slicing for
the mount-name + relative-path split. Zero alloc instead of allocating
a 2-element []string. Every Data.ReadFile / ReadString / List /
ListNames / Mounts call benefits.
* Embed.path — skip PathJoin when basedir is "" or ".". The canonical
Mount(fsys, ".") shape is hot and that PathJoin alloc was per-call.
* log writeKV — replace Sprintf("%q") / Sprintf("%v") with
strconv.AppendQuote / AppendInt / AppendUint / AppendBool /
AppendFloat into a stack-allocated 64-byte scratch. Zero alloc per
keyval for string / int / int64 / uint / uint64 / bool / float64
(the >99% of real log values). Non-trivial types still go through
Sprintf to preserve behaviour.
Bench impact (Apple M3 Ultra):
Data.ReadFile_Hit 299 ns / 9 allocs → 187 ns / 5 allocs 1.6x
Data.ReadString_Hit 355 ns / 11 allocs → 207 ns / 7 allocs 1.7x
Data.List 484 ns / 13 allocs → 375 ns / 9 allocs 1.3x
Embed.ReadFile 251 ns / 8 allocs → 162 ns / 5 allocs 1.5x
Embed.ReadString 274 ns / 10 allocs → 186 ns / 7 allocs 1.5x
Embed.Sub 187 ns / 5 allocs → 73 ns / 3 allocs 2.6x
Log.Info_TwoKeyvals 273 ns / 5 allocs → 188 ns / 2 allocs 1.5x
Log.Warn_SixKeyvals 585 ns / 11 allocs → 345 ns / 2 allocs 1.7x
Log.Security 305 ns / 6 allocs → 202 ns / 2 allocs 1.5x
Log.LogErr_Log 416 ns / 9 allocs → 290 ns / 4 allocs 1.4x1 parent 0a8b115 commit d9522dc
3 files changed
Lines changed: 46 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
| 75 | + | |
74 | 76 | | |
75 | | - | |
76 | | - | |
| 77 | + | |
| 78 | + | |
77 | 79 | | |
78 | 80 | | |
79 | | - | |
| 81 | + | |
80 | 82 | | |
81 | 83 | | |
82 | 84 | | |
83 | | - | |
| 85 | + | |
84 | 86 | | |
85 | 87 | | |
86 | 88 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
390 | 390 | | |
391 | 391 | | |
392 | 392 | | |
393 | | - | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
394 | 406 | | |
395 | 407 | | |
396 | 408 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
248 | 249 | | |
249 | 250 | | |
250 | 251 | | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
251 | 257 | | |
252 | 258 | | |
253 | 259 | | |
| |||
266 | 272 | | |
267 | 273 | | |
268 | 274 | | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
275 | 296 | | |
276 | 297 | | |
277 | 298 | | |
| |||
0 commit comments