Commit 3b3f8d9
authored
refactor(header): replace IsEmptyBlock with fast IsZero short-circuit (#2547)
`IsEmptyBlock` was the per-block hot path of
`DiffMetadataBuilder.Process` — one call per block during the rootfs
scan in `DirectProvider.exportToDiff`. It paid a full SIMD `memcmp` (4
KiB or, on hugepages, 2 MiB) before it could short-circuit, and required
two static zero buffers (`EmptyBlock`, `EmptyHugePage`) to compare
against.
Replace it with a small `IsZero` helper that uses QEMU's
`buffer_is_zero` trick: sample three bytes (first, last, middle) so most
non-zero blocks reject from a single cache line. The fallback uses
`bytes.Equal` on `b` shifted by one (`b[1:] == b[:n-1]`), which
dispatches to the runtime's SIMD `memequal` on amd64/arm64 — same speed
as the old comparison against a static buffer when the short-circuit
doesn't fire.
`DiffMetadataBuilder.Process` calls `IsZero` directly (the size
validation `IsEmptyBlock` did was unreachable in practice). `EmptyBlock`
is removed; `EmptyHugePage` stays — `build.go` uses it as the literal
zero buffer for `uuid.Nil` reads in `Build.ReadAt`.
Pre-factored from #2546 so it can land on its own.1 parent b2208ff commit 3b3f8d9
3 files changed
Lines changed: 42 additions & 20 deletions
File tree
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
| |||
15 | 14 | | |
16 | 15 | | |
17 | 16 | | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
| 17 | + | |
22 | 18 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
32 | 34 | | |
33 | 35 | | |
34 | | - | |
| 36 | + | |
35 | 37 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
| 135 | + | |
140 | 136 | | |
141 | 137 | | |
142 | 138 | | |
| |||
0 commit comments