Skip to content

Commit f323d41

Browse files
authored
Merge pull request #17 from go-faster/feat/speedup-ipv6
feat(proto): improve IPv6 column speed
2 parents 69a2fcf + fd47dd1 commit f323d41

File tree

9 files changed

+263
-234
lines changed

9 files changed

+263
-234
lines changed

proto/_golden/col_arr_ipv6.hex

+149-149
Large diffs are not rendered by default.

proto/_golden/col_arr_ipv6.raw

0 Bytes
Binary file not shown.

proto/_golden/col_ipv6.hex

+49-49
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
11
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
2-
00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 |................|
3-
00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 |................|
4-
00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 |................|
5-
00000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 |................|
6-
00000050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 |................|
7-
00000060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 06 |................|
8-
00000070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 07 |................|
9-
00000080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 |................|
10-
00000090 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 09 |................|
11-
000000a0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0a |................|
12-
000000b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0b |................|
13-
000000c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0c |................|
14-
000000d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0d |................|
15-
000000e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0e |................|
16-
000000f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0f |................|
17-
00000100 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10 |................|
18-
00000110 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 11 |................|
19-
00000120 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 12 |................|
20-
00000130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 13 |................|
21-
00000140 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 14 |................|
22-
00000150 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 15 |................|
23-
00000160 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 16 |................|
24-
00000170 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 17 |................|
25-
00000180 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 18 |................|
26-
00000190 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 19 |................|
27-
000001a0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1a |................|
28-
000001b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1b |................|
29-
000001c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1c |................|
30-
000001d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1d |................|
31-
000001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1e |................|
32-
000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1f |................|
33-
00000200 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 20 |............... |
34-
00000210 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 21 |...............!|
35-
00000220 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 22 |..............."|
36-
00000230 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 23 |...............#|
37-
00000240 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 24 |...............$|
38-
00000250 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 25 |...............%|
39-
00000260 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 26 |...............&|
40-
00000270 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 27 |...............'|
41-
00000280 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 28 |...............(|
42-
00000290 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 29 |...............)|
43-
000002a0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2a |...............*|
44-
000002b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2b |...............+|
45-
000002c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2c |...............,|
46-
000002d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2d |...............-|
47-
000002e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2e |................|
48-
000002f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2f |.............../|
49-
00000300 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 |...............0|
50-
00000310 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 31 |...............1|
2+
00000010 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 |................|
3+
00000020 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 |................|
4+
00000030 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 |................|
5+
00000040 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 |................|
6+
00000050 00 00 00 00 00 00 00 05 00 00 00 00 00 00 00 00 |................|
7+
00000060 00 00 00 00 00 00 00 06 00 00 00 00 00 00 00 00 |................|
8+
00000070 00 00 00 00 00 00 00 07 00 00 00 00 00 00 00 00 |................|
9+
00000080 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 00 |................|
10+
00000090 00 00 00 00 00 00 00 09 00 00 00 00 00 00 00 00 |................|
11+
000000a0 00 00 00 00 00 00 00 0a 00 00 00 00 00 00 00 00 |................|
12+
000000b0 00 00 00 00 00 00 00 0b 00 00 00 00 00 00 00 00 |................|
13+
000000c0 00 00 00 00 00 00 00 0c 00 00 00 00 00 00 00 00 |................|
14+
000000d0 00 00 00 00 00 00 00 0d 00 00 00 00 00 00 00 00 |................|
15+
000000e0 00 00 00 00 00 00 00 0e 00 00 00 00 00 00 00 00 |................|
16+
000000f0 00 00 00 00 00 00 00 0f 00 00 00 00 00 00 00 00 |................|
17+
00000100 00 00 00 00 00 00 00 10 00 00 00 00 00 00 00 00 |................|
18+
00000110 00 00 00 00 00 00 00 11 00 00 00 00 00 00 00 00 |................|
19+
00000120 00 00 00 00 00 00 00 12 00 00 00 00 00 00 00 00 |................|
20+
00000130 00 00 00 00 00 00 00 13 00 00 00 00 00 00 00 00 |................|
21+
00000140 00 00 00 00 00 00 00 14 00 00 00 00 00 00 00 00 |................|
22+
00000150 00 00 00 00 00 00 00 15 00 00 00 00 00 00 00 00 |................|
23+
00000160 00 00 00 00 00 00 00 16 00 00 00 00 00 00 00 00 |................|
24+
00000170 00 00 00 00 00 00 00 17 00 00 00 00 00 00 00 00 |................|
25+
00000180 00 00 00 00 00 00 00 18 00 00 00 00 00 00 00 00 |................|
26+
00000190 00 00 00 00 00 00 00 19 00 00 00 00 00 00 00 00 |................|
27+
000001a0 00 00 00 00 00 00 00 1a 00 00 00 00 00 00 00 00 |................|
28+
000001b0 00 00 00 00 00 00 00 1b 00 00 00 00 00 00 00 00 |................|
29+
000001c0 00 00 00 00 00 00 00 1c 00 00 00 00 00 00 00 00 |................|
30+
000001d0 00 00 00 00 00 00 00 1d 00 00 00 00 00 00 00 00 |................|
31+
000001e0 00 00 00 00 00 00 00 1e 00 00 00 00 00 00 00 00 |................|
32+
000001f0 00 00 00 00 00 00 00 1f 00 00 00 00 00 00 00 00 |................|
33+
00000200 00 00 00 00 00 00 00 20 00 00 00 00 00 00 00 00 |....... ........|
34+
00000210 00 00 00 00 00 00 00 21 00 00 00 00 00 00 00 00 |.......!........|
35+
00000220 00 00 00 00 00 00 00 22 00 00 00 00 00 00 00 00 |......."........|
36+
00000230 00 00 00 00 00 00 00 23 00 00 00 00 00 00 00 00 |.......#........|
37+
00000240 00 00 00 00 00 00 00 24 00 00 00 00 00 00 00 00 |.......$........|
38+
00000250 00 00 00 00 00 00 00 25 00 00 00 00 00 00 00 00 |.......%........|
39+
00000260 00 00 00 00 00 00 00 26 00 00 00 00 00 00 00 00 |.......&........|
40+
00000270 00 00 00 00 00 00 00 27 00 00 00 00 00 00 00 00 |.......'........|
41+
00000280 00 00 00 00 00 00 00 28 00 00 00 00 00 00 00 00 |.......(........|
42+
00000290 00 00 00 00 00 00 00 29 00 00 00 00 00 00 00 00 |.......)........|
43+
000002a0 00 00 00 00 00 00 00 2a 00 00 00 00 00 00 00 00 |.......*........|
44+
000002b0 00 00 00 00 00 00 00 2b 00 00 00 00 00 00 00 00 |.......+........|
45+
000002c0 00 00 00 00 00 00 00 2c 00 00 00 00 00 00 00 00 |.......,........|
46+
000002d0 00 00 00 00 00 00 00 2d 00 00 00 00 00 00 00 00 |.......-........|
47+
000002e0 00 00 00 00 00 00 00 2e 00 00 00 00 00 00 00 00 |................|
48+
000002f0 00 00 00 00 00 00 00 2f 00 00 00 00 00 00 00 00 |......./........|
49+
00000300 00 00 00 00 00 00 00 30 00 00 00 00 00 00 00 00 |.......0........|
50+
00000310 00 00 00 00 00 00 00 31 00 00 00 00 00 00 00 00 |.......1........|

proto/_golden/col_ipv6.raw

0 Bytes
Binary file not shown.

proto/cmd/ch-gen-col/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ func run() error {
318318
}
319319
}
320320
for _, v := range variants {
321-
if !v.Byte() && !v.IPv6() {
321+
if !v.Byte() {
322322
v.GenerateUnsafe = true
323323
}
324324
base := "col_" + v.ElemLower()

proto/col_ipv6_safe_gen.go

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/col_ipv6_unsafe_gen.go

+44
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/ipv6.go

+6-34
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,19 @@
11
package proto
22

33
import (
4-
"encoding/binary"
5-
64
"inet.af/netaddr"
75
)
86

9-
// IPv6 represents UInt128 address as UInt128 number.
10-
//
11-
// Not using netaddr.IP because UInt128 is more efficient.
12-
//
13-
// Use ToIP helper for convenience.
14-
type IPv6 UInt128
7+
// IPv6 represents IPv6 address.
8+
type IPv6 [16]byte
159

1610
// ToIP represents IPv6 as netaddr.IP.
1711
func (v IPv6) ToIP() netaddr.IP {
18-
var buf [16]byte
19-
binary.BigEndian.PutUint64(buf[0:8], v.High)
20-
binary.BigEndian.PutUint64(buf[8:16], v.Low)
21-
return netaddr.IPv6Raw(buf)
12+
return netaddr.IPv6Raw(v)
2213
}
2314

2415
// ToIPv6 represents ip as IPv6.
25-
func ToIPv6(ip netaddr.IP) IPv6 {
26-
b := ip.As16()
27-
return IPv6{
28-
High: binary.BigEndian.Uint64(b[0:8]),
29-
Low: binary.BigEndian.Uint64(b[8:16]),
30-
}
31-
}
16+
func ToIPv6(ip netaddr.IP) IPv6 { return ip.As16() }
3217

33-
func binIPv6(b []byte) IPv6 {
34-
_ = b[:16] // bounds check hint to compiler; see golang.org/issue/14808
35-
// Using BigEndian for IPv6 as per ClickHouse implementation.
36-
return IPv6{
37-
High: binary.BigEndian.Uint64(b[0:8]),
38-
Low: binary.BigEndian.Uint64(b[8:16]),
39-
}
40-
}
41-
42-
func binPutIPv6(b []byte, v IPv6) {
43-
_ = b[:16] // bounds check hint to compiler; see golang.org/issue/14808
44-
// Using BigEndian for IPv6 as per ClickHouse implementation.
45-
binary.BigEndian.PutUint64(b[0:8], v.High)
46-
binary.BigEndian.PutUint64(b[8:16], v.Low)
47-
}
18+
func binIPv6(b []byte) IPv6 { return *(*[16]byte)(b) }
19+
func binPutIPv6(b []byte, v IPv6) { copy(b, v[:]) }

proto/ipv6_test.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package proto
22

33
import (
44
"bytes"
5+
"encoding/binary"
56
"testing"
67

78
"github.com/stretchr/testify/require"
@@ -11,7 +12,17 @@ import (
1112
)
1213

1314
func IPv6FromInt(v int) IPv6 {
14-
return IPv6(UInt128FromInt(v))
15+
s := IPv6{}
16+
binary.BigEndian.PutUint64(s[:], uint64(v))
17+
return s
18+
}
19+
20+
func TestToIPv6(t *testing.T) {
21+
v := netaddr.MustParseIP("2001:db8:ac10:fe01:feed:babe:cafe:0")
22+
b := make([]byte, 16)
23+
binPutIPv6(b, v.As16())
24+
ip := binIPv6(b)
25+
require.Equal(t, v, ip.ToIP())
1526
}
1627

1728
func TestColIPv6_NetAddr(t *testing.T) {

0 commit comments

Comments
 (0)